Suppose we have a dictionary inp = {"virat":60,"rohit":50,"sardhul":50,"rana":60}
and
we should get the output as {60: ['virat', 'rana'], 50: ['rohit', 'sardhul']}
I can do it in normal python programming as follows
out = dict()
for key, val in inp.items():
if val not in out:
out[val] = [key]
else:
out[val].append(key)
The output is {60: ['virat', 'rana'], 50: ['rohit', 'sardhul']}
How can we do the same in dictionary comprehension?