Create a variable number of dictionary whose name comes from the list in Python

advertisements

I have a list which grows and shrinks in a for loop. The list looks like following :- . With every element inside list of list i want to associate it to a separate dictionary.

list123 = [[1010,0101],[0111,1000]]

In this case I want to create 4 dictionary with the following name

dict1010 = {}
dict0101 = {}
dict0111 = {}
dict1000 = {}

I tried following loop

for list1 in list123:
    for element in list1:
        dict + str(element) = dict()

This is the error i am getting

SyntaxError: can't assign to literal


while you can dynamically create variables, unless there is an overwhelming need to do that use instead a dictionary of dictionary witch key is the name you want, like this

my_dicts=dict()
for list1 in list123:
    for element in list1:
        my_dicts["dict" + str(element)] = dict()

and to access one of them do for example my_dicts["dict1010"]