-2

Need you help to get an idea how to update dictionary value that represented as dictinary.

Here are two dictionaries: d1 = {'x': {'y': 5}} d2 = {'x': {'z': 6}}

Assume d1 + d2, then dictionary = {'x': {'y': 5, 'z': 6}}

Thank you.

1 Answers1

0

It's rather simple...

d1['x'].update(d2['x'])

or for all keys:

[d1[k].update(d2[k]) for k in d1]
Shashank
  • 13,713
  • 5
  • 37
  • 63