Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • 3
    This does not answer the question. The question clearly asks for a new dictionary, z, from original dictionaries, x and y, with values from y replacing those of x - not an updated dictionary. This answer modifies y in-place by adding values from x. Worse, it does not copy these values, so one could further modify the modified dictionary, y, and modifications could be reflected in dictionary x. @Jérôme I hope this code is not causing any bugs for your application - at least consider using deepcopy to copy the values.
    – Aaron Hall
    Commented Nov 9, 2018 at 2:14
  • 3
    @AaronHall agreed this does not answer the question. But it answers my need. I understand those limitations, but that's not an issue in my case. Thinking of it, maybe the name is misleading, as it might evoke a deepcopy, which it does not provide. But it addresses deep nesting. Here's another implementation from the Martellibot: stackoverflow.com/questions/3232943/….
    – Jérôme
    Commented Nov 9, 2018 at 13:24
  • In python 3.8.2 it gives me AttributeError: 'dict' object has no attribute 'iteritems' so I have changes the iteritems with items.
    – thanos.a
    Commented Mar 3 at 17:18