Hope this is a straightforward issue:
Here is my dictionary temp = {'0.1995': ['in1', 'in2'], '0.399': ['in0', 'y']})
code to search file:
for line in SPFFile:
temp_dict = temp
for val in temp_dict.itervalues():
if re.search(val.upper(),line) and ((re.search("^R",line) or re.search("^C",line))):
print "value found!"
My problem is that val is a list such as [‘in1′,’in2’] while I need val to be ‘in1’ then ‘in2’ and so forth.
Also if I shouldn’t be using a dictionary to do this please let me know. The dictionary was formed from two lists.
Change your inner
forloop to:As for using a dictionary in the first place, it all depends on whether you need your values organized via keys as you have above. If you’re just trying to check if any of the values is present in a given line, it might be better to
'|'.join()all the values together and use the resulting string as your search expression.