I have a txt file with a lot of lines like this
369136986 cms_trk_dcs_05:CAEN/CMS_TRACKER_SY1527_8/branchController05/easyCrate1/easyBoard03/channel002
Two columns where the first has numbers, and the second column a line with properties separated by /, both columns are separated by space.
I did a dictionary of dictionaries where the key1 is
the first number that appears in the line (369136986), this key has as a value the other dictionary, where the keys are cmstrk, trackersy, branch, crate, board, channel and each of these keys key has as a value cms_trk_dcs_05:CAEN, CMS_TRACKER_SY1527_8, branchController05, easyCrate1, easyBoard03, channel002, respectively, so if you ask cmstrk (key2) for 369136986 (key1) it returns cms_trk_dcs_05 (value).
How can I get the key by giving the value? I mean if I give the value CMS_TRACKER_SY1527_8 I need to know to which key1 corresponds (the program should return 369136986).
This is what i tried:
input3=raw_input("Write the property(s) which modules connected you want to know, separated by a single space \n > ")
input_list3=input3.split(' ')
for k in input_list3:
print "%r" % k
txt.write("\t\n The modules with property %r are:\n" % k)
for l,m in zip(HVInfoDict.keys(),HVInfoDict.values()):
if k == HVInfoDict[l][m]:
print l
but it returns
TypeError: unhashable type: 'dict'
so how can I get the first key?
if k in m.values():get you what you want?mis sometimes a dictionary, which can't be used as a key to another dictionary.zip(HVInfoDict.keys(),HVInfoDict.values())byHVInfoDict.items(), as it will return same list of tuples.