Fix Python – Adding dictionaries together [duplicate]


Asked By – rectangletangle

I have two dictionaries and I’d like to be able to make them one:

Something like this pseudo-Python would be nice:

dic0 = {'dic0': 0}
dic1 = {'dic1': 1}

ndic = dic0 + dic1
# ndic would equal {'dic0': 0, 'dic1': 1}

Now we will see solution for issue: Adding dictionaries together [duplicate]


If you’re interested in creating a new dict without using intermediary storage: (this is faster, and in my opinion, cleaner than using dict.items())

dic2 = dict(dic0, **dic1)

Or if you’re happy to use one of the existing dicts:


This question is answered By – bluepnume

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0