Dicts упорядочены в Python 3.6+, так что вы можете просто отсортировать элементы dict с помощью пользовательского ключа:
d = {'Ariana Greenblatt': ['Young Gamora', 341], 'Stan Lee': ['Schoolbus Driver', 335], 'Anthony Mackie': ['Sam Wilson / Falcon', 70], 'Chadwick Boseman': ["T'Challa / Black Panther", 46], 'Letitia Wright': ['Shuri', 90], 'Ameenah Kaplan': ["Gamora's Mother", 342], 'Florence Kasumba': ['Ayo', 114], 'Carrie Coon': ['Proxima Midnight (voice)', 329], 'Samuel L. Jackson': ['Nick Fury (uncredited)', 332], 'Kenneth Branagh': ['Asgardian Distress Call (voice) (uncredited)', 357], 'Chris Evans': ['Steve Rogers / Captain America', 2], 'Chris Hemsworth': ['Thor Odinson', 6], 'Tom Vaughan-Lawlor': ['Ebony Maw', 97], 'Robert Pralgo': ['Thanos Reader', 344]}
print(dict(sorted(d.items(), key=lambda x: x[1][1])))
Это выводит:
{'Chris Evans': ['Steve Rogers / Captain America', 2], 'Chris Hemsworth': ['Thor Odinson', 6], 'Chadwick Boseman': ["T'Challa / Black Panther", 46], 'Anthony Mackie': ['Sam Wilson / Falcon', 70], 'Letitia Wright': ['Shuri', 90], 'Tom Vaughan-Lawlor': ['Ebony Maw', 97], 'Florence Kasumba': ['Ayo', 114], 'Carrie Coon': ['Proxima Midnight (voice)', 329], 'Samuel L. Jackson': ['Nick Fury (uncredited)', 332], 'Stan Lee': ['Schoolbus Driver', 335], 'Ariana Greenblatt': ['Young Gamora', 341], 'Ameenah Kaplan': ["Gamora's Mother", 342], 'Robert Pralgo': ['Thanos Reader', 344], 'Kenneth Branagh': ['Asgardian Distress Call (voice) (uncredited)', 357]}
или до Python 3.6, вы можете использовать collections.OrderedDict
вместо:
from collections import OrderedDict
d = OrderedDict([('Ariana Greenblatt', ['Young Gamora', 341]), ('Stan Lee', ['Schoolbus Driver', 335]), ('Anthony Mackie', ['Sam Wilson / Falcon', 70]), ('Chadwick Boseman', ["T'Challa / Black Panther", 46]), ('Letitia Wright', ['Shuri', 90]), ('Ameenah Kaplan', ["Gamora's Mother", 342]), ('Florence Kasumba', ['Ayo', 114]), ('Carrie Coon', ['Proxima Midnight (voice)', 329]), ('Samuel L. Jackson', ['Nick Fury (uncredited)', 332]), ('Kenneth Branagh', ['Asgardian Distress Call (voice) (uncredited)', 357]), ('Chris Evans', ['Steve Rogers / Captain America', 2]), ('Chris Hemsworth', ['Thor Odinson', 6]), ('Tom Vaughan-Lawlor', ['Ebony Maw', 97]), ('Robert Pralgo', ['Thanos Reader', 344])])
print(OrderedDict(sorted(d.items(), key=lambda x: x[1][1])))