In response to asking for an example, you could use list comprehensions to get technically more compact code. I don't think they add much here (although they are likely more efficient for huge data sets if we were to profile them).
They do make the code harder to read, so I'm really not a fan of that approach here for most situations.
If you feel like your solution is strung together and you can control the persistence code, store the data in a standard format.
from collections import defaultdict
outdict = defaultdict(list)
def getkeybyvalue(dictionary, value):
return [i for i,j in dictionary.items() if value in j]
dict_from_file = """foo\tfoobar, bar, foo foo\tFoo bar language, computing\nprog\t python, java, c, c++\t computing\nedibles\tcereal, milk, whatever\tfood"""
columns = [line.strip().split('\t') for line in dict_from_file.split('\n')]
for c1, c2, c3 in columns:
for c3_item in c3.split(','):
outdict[c3_item.strip(', ')] += [c1] + [c.strip(' ,') for c in c2.split(',')]
for k in outdict:
print(k, outdict[k])
print(getkeybyvalue(outdict, 'foo foo'))