I'm not sure if a dictionary is the way to go, but I made a dictionary that contains a list of 1-7 items. I would like to access the key given any of the items in the list. Is this possible? I found a way to access a key given one value (Get key by value in dictionary), but what if there are multiple values? My end goal is to repeat a string (String A) given a separate string, (String B) that is categorized under String A. For example, 'Category A' contains aa, bb, cc and 'Cateogry B' contains a, b, c. A list of [aa, a, bb, aa, c, b, aa] would equal to: [A, B, A, A, B, B, A]. This is my attempt so far, however it does not work.
dict = {'A':['aa', 'bb', 'cc'],'B':['a','b','c'] }
nwlst = []
lst = [aa, a, bb, aa, c, b, aa]
for i in lst:
if i in dict.values():
nwlst.append([list(dict.keys())[list(dict.values()).index([str(i)])]])
Perhaps using something like grep could work too but I don't know how to implement this concept.