say i have a dictionary like this:
{'etova ER400': 'rack1', 'enzomac forte': 'rack1', 'myosone': 'rack1', 'etova 200': 'rack2', 'etogesic ER': 'rack2'}
and Now,if my searchQuery says 'eto'; am getting the related VALUE in the output
Q: But how to get the list of all the keys for that particular VALUE as well say if the searchQuery says 'enzomac', OUTPUT: enzomac forte ---> rack1 ; and rack1 -> ['etova ER400', 'enzomac forte','myosone']
i tried this:
rev_dict = {}
flipped={}
myDict = {}
def get_key(val):
if val not in flipped:
flipped[val] = [key]
else:
flipped[val].append(key)
return(flipped)
myDict.update(dict.fromkeys(['etova ER400', 'enzomac forte','myosone'], 'rack1'))
myDict.update(dict.fromkeys(['etova 200','etogesic ER'], 'rack2'))
search_key = input("Enter name of med : ").lower()
for key, val in myDict.items():
if key.startswith(search_key):
print(key, " ---> ", val)
rev_dict=get_key(val)
print(rev_dict)