Skip to content

Instantly share code, notes, and snippets.

@SaraM92
Last active March 9, 2023 14:27
Show Gist options
  • Save SaraM92/86da0ae9383f493ad5680c8f3021c039 to your computer and use it in GitHub Desktop.
Save SaraM92/86da0ae9383f493ad5680c8f3021c039 to your computer and use it in GitHub Desktop.
from collections import defaultdict
#merge two or more dicts using the collections module
def merge_dicts(*dicts):
mdict = defaultdict(list)
for d in dicts:
for key in d:
mdict[key].append(d[key])
return dict(mdict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment