Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (16.4k points)

Hello, all

Let's say I have a Dictionary:


Now, I just want to create an array with many dictionaries, as follows:


Have a look at my code:

weightMatrix = []

for k in range(motifWidth):

    weightMatrix[k] = {'A':0,'C':0,'G':0,'T':0}

But, I know it isn't working.

Can anyone give me some suggestions?

Thanks in Advance :)

1 Answer

0 votes
by (26.4k points)
edited by

Try in this way and I think, this works:

dictlist = [dict() for x in range(n)]

This will give you a list of n number of empty dictionaries

If you want to learn about Python, you can come & join: Python training course

For more details, do check out our tutorial:

Browse Categories