Skip to content

Instantly share code, notes, and snippets.

@grizwako
Created February 22, 2018 20:25
Show Gist options
  • Save grizwako/239980ce4789ac6dbb0b7e4488003332 to your computer and use it in GitHub Desktop.
Save grizwako/239980ce4789ac6dbb0b7e4488003332 to your computer and use it in GitHub Desktop.
from collections import defaultdict
def group_products_by_locations(locations_by_product):
products_by_locations = defaultdict(list)
for product, locations in locations_by_product.items():
for location in locations:
products_by_locations[location].append(product)
return products_by_locations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment