'How to reverse the key value pairs of a dictionary? [duplicate]

Given dictionary is d1={"a":1,"b":2,"c":3,"d":4,"e":4} convert the same to {1:"a",2:"b",3:"c",4:["d","e"]}

I have tried and I just got reverse string using key value pair

dictionary={"a":1,"b":2,"c":2}
r_dictionary={value:key for key, value in dictionary.items()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source