Skip to content

Instantly share code, notes, and snippets.

@michaelteter
Created May 28, 2018 20:13
Show Gist options
  • Save michaelteter/a08c553916b424542834f300e14b193e to your computer and use it in GitHub Desktop.
Save michaelteter/a08c553916b424542834f300e14b193e to your computer and use it in GitHub Desktop.
# There are many ways to do this, but without knowing circumstantial constraints I chose simple/brute-force.
def activities_by_location(activities):
locations = {}
for k,v in activities.items():
for location in v:
if location not in locations:
locations[location] = []
locations[location].append(k)
return locations
activities = {"skiing": ["Winter Park", "Park City", "Saalbach"],
"surfing": ["Maui", "Arrifana"],
"mountain biking": ["Winter Park", "Park City", "Moab", "Maui"]}
print(activities_by_location(activities))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment