【发布时间】:2021-06-30 05:35:57
【问题描述】:
dict={"a":[1,2,3,12],"b":[5,6,7,8],"c":[9,10,11,4]}
这是我的字典,我想按每个值列表的最后一个索引对dict 进行排序...可以吗?
我的意思是我想按这个数字 4、8、12 对dict 进行排序并打印出来。
所以输出将是:
{'a': [9, 10, 11, 4], 'b': [5, 6, 7, 8], 'c': [1,2,3,12]}
【问题讨论】:
-
dicts 根据定义 无序 -
您可以通过在 3.7+ 但 there's probably a better way to do whatever you're trying to do 中插入来依赖 dict 排序。考虑展示尝试或更多背景信息以提高您收到的答案的质量。谢谢。
标签: python-3.x dictionary