Last active
July 26, 2018 14:31
-
-
Save CrazyPython/dac5e6c000fa5d021dcd18c91bfea76e to your computer and use it in GitHub Desktop.
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
from collections import defaultdict | |
output = defaultdict(list) | |
for item in data: | |
output[item["owner"]].append(item["pet"]) | |
# output is => | |
defaultdict(list, | |
{'Kent': ['Shiner'], | |
'Mary': ['Pumpkin', 'Tasha'], | |
'Paige': ['Sushi'], | |
'Sarah': ['Shiner', 'Mr. Wigglesworth', 'Pupparoo', 'Lucy']}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment