Created
March 21, 2015 23:04
-
-
Save bittner/012d0287ebdcacdab95a to your computer and use it in GitHub Desktop.
How do I merge dictionaries the pythonic way?
Source: http://stackoverflow.com/questions/38987/how-can-i-merge-two-python-dictionaries-in-a-single-expression/26853961#26853961
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 merge_dicts(*dict_args): | |
""" | |
Given any number of dicts, shallow copy and merge into a new dict, | |
precedence goes to key value pairs in latter dicts. | |
""" | |
result = {} | |
for dictionary in dict_args: | |
result.update(dictionary) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment