How can I add a dictionary to each element of a dictionary of dictionaries?
dict_of_dict = {
'PERCY': {'Asset': 'PERCY', 'Win': 3, 'Door': 10},
'FRANK': {'Asset': 'FRANK', 'Win': 5, 'Door': 0.7}
}
print(dict_of_dict)
print("")
new_bit={'Chunk': ['A','B','C']}
print(new_bit)
print("")
cfg = {key:value.update(new_bit) for (key, value) in dict_of_dict.items()}
print(cfg)
print("")
what_i_want= {
'PERCY': {'Asset': 'PERCY', 'Win': 3, 'Door': 10,'Chunk': ['A','B','C']},
'FRANK': {'Asset': 'FRANK', 'Win': 5, 'Door': 0.7,'Chunk': ['A','B','C']}
}
print(what_i_want)
I am trying to use comprehension, I get cfg
but it is not correct I need what_i_want
Output:
dict_of_dict:
{'PERCY': {'Asset': 'PERCY', 'Win': 3, 'Door': 10},
'FRANK': {'Asset': 'FRANK', 'Win': 5, 'Door': 0.7}}
new_bit:
{'Chunk': ['A', 'B', 'C']}
cfg:
{'PERCY': None, 'FRANK': None}
what_i_want:
{'PERCY': {'Asset': 'PERCY', 'Win': 3, 'Door': 10, 'Chunk': ['A', 'B', 'C']},
'FRANK': {'Asset': 'FRANK', 'Win': 5, 'Door': 0.7, 'Chunk': ['A', 'B', 'C']}}