Intellipaat Back

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

Hello, all

Let's say I have a Dictionary:

{'S':0,'H':0,'A':0,'L':0}

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

[{'S':0,'H':0,'A':0,'L':0},{'S':0,'H':0,'A':0,'L':0},{'S':0,'H':0,'A':0,'L':0},....]

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:

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...