Skip to content

Instantly share code, notes, and snippets.

@emmanuellyautomated
Created October 24, 2016 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emmanuellyautomated/8698147d6dbb1d88ff8a1a4107d7d43f to your computer and use it in GitHub Desktop.
Save emmanuellyautomated/8698147d6dbb1d88ff8a1a4107d7d43f to your computer and use it in GitHub Desktop.
For dictionaries having arrays as values, this function merges arrays of different dictionaries belonging to the same key. It *does* overwrite the first one though so beware!
def merge_dicts_arrs(d1, d2):
for k,v in d2.items():
if k in d1.keys():
d1[k] = d1[k] + d2[k]
else:
d1.update({k:v})
return d1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment