Created
May 7, 2014 01:05
-
-
Save skamithi/6dd83f2c6f73cf0a2130 to your computer and use it in GitHub Desktop.
Python Merge simple dictionaries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def dict_merge(list1, list2): | |
""" Trick is to use the .__dict__ keyword. This puts all the attrs associated with | |
this library's instance are part of the mergin algorithm | |
_keys = list2.keys() | |
try _key in keys: | |
try: | |
list1[key].__dict__.update(list2[__key].__dict__) | |
except: | |
list[_key] = list2[_key] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment