So, I have this index as a dict.
index = {\'Testfil2.txt\': [\'nisse\', \'hue\', \'abe\', \'pind\'], \'Testfil1.txt\': [\'hue\', \'abe\',
\'tosse\', \'svend
I've tried around and you want to use val not in inverse but it can't be checked if a "list is in a dict". (val is a list)
For your code a simple change will do what you want:
def invert_dict(d):
inverse = dict()
for key in d:
# Go through the list that is saved in the dict:
for item in d[key]:
# Check if in the inverted dict the key exists
if item not in inverse:
# If not create a new list
inverse[item] = [key]
else:
inverse[item].append(key)
return inverse