I'm trying to create a nested dictionary from a list of strings. Each index of the strings corresponds to a key, while each character a value.
I have a list:
list = ['game', 'club', 'party', 'play']
I would like to create a (nested) dictionary:
dict = {0: {'g', 'c', 'p', 'p'}, 1: {'a', 'l', 'a', 'l'}, 2: {'m', 'u', 'r', 'a'}, etc.}
I was thinking something along the lines of:
res = {}
for item in range(len(list)):
for i in list[item]:
if i not in res:
# create a key (index - ex. '0') and a value (character - ex. 'g' of 'game')
else:
# put the value in the corresponding key (ex. 'c' of 'club')
print(res)
sets as the values to your keys?{'a', 'l', 'a', 'l'}