x = {'Jackie': 176, 'Wilson': 185, 'Saersha': 165,'Roman': 185,'Abram': 169}
y = [(v, k) for k, v in x.items()] # creates a list of tuples as (value, key) pair
y.sort(reverse = True) # sorts the items in a list
# creates a dictionary with key as value from list(x) and value as a list of key from list(x)
z = {}
for a in y:
if a[0] in z:
z[a[0]].append(a[1])
else:
z[a[0]] = [a[1]]
print(z)
Разве вывод не должен быть:
{185: ['Wilson', 'Roman'], 176: ['Jackie'], 169: ['Abram'], 165: ['Saersha']}
Вместо этого он выглядит так:
{176: ['Jackie'], 185: ['Wilson', 'Roman'], 165: ['Saersha'], 169: ['Abram']}