Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (12.7k 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:

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...