Created
May 13, 2018 12:33
-
-
Save harshvb7/95ebb2e69996f1c234d3b1bc3134f801 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
class Solution(object): | |
def __init__(self): | |
self.arr = [] | |
def add_product(self, name, locations): | |
self.arr.append((name, locations)) | |
def get_locations(self): | |
data = {} | |
for item in self.arr: | |
for location in item[1]: | |
if location not in data: | |
data[location] = set() | |
data[location].add(item[0]) | |
return [(x[0], list(x[1])) for x in data.items()] | |
s = Solution() | |
s.add_product('ABC', ["Paris", "France", "Europe"]) | |
s.add_product('DEF', ["Dubai", "Abu Dhabi", "UAE"]) | |
s.add_product('XYZ', ["Germany", "Italy", "Paris", "Europe"]) | |
print s.get_locations() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment