Skip to content

Instantly share code, notes, and snippets.

@CrazyPython
Last active July 26, 2018 14:31
Show Gist options
  • Save CrazyPython/dac5e6c000fa5d021dcd18c91bfea76e to your computer and use it in GitHub Desktop.
Save CrazyPython/dac5e6c000fa5d021dcd18c91bfea76e to your computer and use it in GitHub Desktop.
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