python按值的长度和字母顺序对字典进行排序

2024-09-29 21:35:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一本字典:

db = {'Carl': [('Intel', 30, 40), ('Dell', 20, 50), ('Intel', -10, 60), ('Apple', 20, 55)], 'Barb': [('Intel', 20, 40), ('Intel', -10, 45), ('IBM', 40, 30), ('Intel', -10, 35)], 'Alan': [('Intel', 20, 10), ('Dell', 10, 50), ('Apple', 80, 80), ('Dell', -10, 55)], 'Dawn': [('Apple', 40, 80), ('Apple', 40, 85), ('Apple', -40, 90)]}

以及一个接受dict参数的函数:

^{pr2}$

我想根据键值的长度按降序返回键列表。我已经在上面的函数中这样做了,但是我不确定如果它们具有相同长度的值,如何按字母顺序递增返回它们。在


Tags: 函数appledb参数字典ibmdictdell

热门问题