我有一个类似的字典:
{1228548: Person(1228548, 'Xantippe', 42.00, 1.10, 96, 56554), 1456010: Person(1456010, 'Mirabelle', 65.00, 2.16, 83, 67906), 1527181: Person(1527181, 'Betteanne', 81.00, 2.09, 43, 62790)...
我希望按照从最低到最高的步数进行排序,这些是值56554,67906和62790 ...在每个Person项目的末尾,我将如何进行此操作?
答案 0 :(得分:1)
而不是迭代人们的(未排序的)词典:
for id_num, person in people.items():
您可以按步数迭代按键排序:
for id_num in sorted(people, key=lambda x: x.total_steps):
p = person_dict[id_num]
#...