Skip to content

Instantly share code, notes, and snippets.

@lee-hodg
Created June 2, 2018 11:54
Show Gist options
  • Save lee-hodg/de2f0eb65eaa7e3161da3f038f3aa752 to your computer and use it in GitHub Desktop.
Save lee-hodg/de2f0eb65eaa7e3161da3f038f3aa752 to your computer and use it in GitHub Desktop.
# Accepts array like [["iPod nano", ["Paris", "France", "Europe"]],
# ["Samsung S8", ["London", "UK", "Europe"]],
# ["Google Pixal", ["Rio", "Brazil", "South America"]]
# ]
from collections import defaultdict
def f(input):
d = defaultdict(set)
for obj in input:
product = obj[0]
locations = obj[1]
for loc in locations:
d[loc].add(product)
return d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment