I need some help in extracting common (shared) values across a python dictionary when I give it a string of text.
Suppose for example that I have a string of text such as:
mylist = ["shirt","pants","shoes","tie","jacket"]
And I also have a list of brands that I have made into dictionary using the dict() function:
shirt Zara
shirt GAP
shirt Old Navy
shirt Banana_Republic
shoes Banana_Republic
shoes Zenga
shoes Zara
shoes Nike
shoes Adidas
tie Hermes
tie Ferragamo
tie Alfani
jacket Alfani
jacket Under_Armour
jacket Nike
jacket Polo
jacket The_North_Face
I need my function to return a list of common brands (any two commonalities) in which a given brand does at least two of the categories in my original list. So for: mylist = ['shirt','shoes','tie','jacket']
someFunction(mylist)
returns:
[‘Zara’,’Banana_Republic’,’Alfani’,’Nike’]
At first I tried writing a forloop which essentially does:
brandDictionary = dict(brands)
def mappings(list, dictionary):
for category in list:
return dictionary[category]
But this returns just one value and I need the string of values
So:
mappings(mylist, brandDictionary)
Gives me:
['Banana_Republic']
And NOT the full list I'm looking for:
[‘Zara’,’Banana_Republic’,’Alfani’,’Nike’]
NOTE ALSO that in $mylist I have "pants" which is NOT stored in my dictionary. This function should just return what values I have matched in my dictionary and not return an error.