I have dict of dict:
a = {
'a': {'id': 1},
'b': {'id': 1},
'c': {'id': 1}
}
And list of dict:
b = [{'word': 'foo'}, {'word': 'baz'}, {'word': 'bar'}]
I need update every dict from a to every value key word from b
Example:
a = {
'a': {'id': 1, 'word': foo},
'b': {'id': 1, 'word': baz},
'c': {'id': 1, 'word': bar}
}
i try do it by the next way:
[
a.update(
{
'word': i
}
)
for a in a.values()
for i in [
df['word'] for df in b
]
]
but i have all new keys with last word bar:
a = {
'a': {'id': 1, 'word': bar},
'b': {'id': 1, 'word': bar},
'c': {'id': 1, 'word': bar}
}
How i can solve it?
Copyright Notice:Content Author:「MrOldSir」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71729433/add-new-key-value-for-every-dict-of-dict-with-list-of-dict