I have a dictionary with values as list of items as shown below :-
{
key1: ['value1', 'value2', 'value3'],
key2: ['value2', 'value3'],
key3: ['value1', 'value2']
}
What I want is to reverse the key-value pair in such a way that, the keys will be now shown in a list format for each value according to its occurrence as shown below :-
{
value1: ['key1', 'key3'],
value2: ['key1', 'key2', 'key3'],
value3: ['key1', 'key2']
}
I know with few iterations using for-loop and if-conditions I can do this, but I was wondering if there is any other optimized way like some built in python tools or something like that to achieve this. Any help would be highly appreciated.