Created
June 2, 2018 11:54
-
-
Save lee-hodg/de2f0eb65eaa7e3161da3f038f3aa752 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
# 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