I'm trying to reverse a dictionary in Python
This is how it should work:
d={'move': ['liikuttaa'], 'hide': ['piilottaa', 'salata'], 'six': ['kuusi'], 'fir': ['kuusi']}
reverse_dictionary(d)
{'liikuttaa': ['move'], 'piilottaa': ['hide'], 'salata': ['hide'], 'kuusi': ['six', 'fir']}
Here is what I have come up with:
def reverse_dictionary(d):
reversed = {value: key for (key, value) in d.items()}
return reversed
def main():
d = {'move': ['liikuttaa'], 'hide': ['piilottaa',
'salata'], 'six': ['kuusi'], 'fir': ['kuusi']}
print(reverse_dictionary(d))
if __name__ == "__main__":
main()
But since the value is in a list, the output results in a TypeError: unhashable type: 'list'. Is there anything I can do to fix this?