Last active
March 9, 2023 14:27
-
-
Save SaraM92/86da0ae9383f493ad5680c8f3021c039 to your computer and use it in GitHub Desktop.
This file contains 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
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