小编Gui*_*ino的帖子

如何根据数值在字典中的数值将具有数字值的字典转换为列表

我有一本字典,其中包含一些字符串作为键,并包含一个数字作为值来充当排名系统,例如某件事的重要性。这是一个例子:

{"eggs": 14, "milk": 8, "flowers":11, "couch":13}
Run Code Online (Sandbox Code Playgroud)

我需要一种将其转换为列表并根据其值进行排序的方法,以使结果为:

["eggs", "couch", "flowers", "milk"]
Run Code Online (Sandbox Code Playgroud)

如您所见,列表顺序基于字典中存在的先前值。有什么我可以使用的吗?

python dictionary list

1
推荐指数
1
解决办法
33
查看次数

标签 统计

dictionary ×1

list ×1

python ×1