【发布时间】:2019-08-10 21:56:50
【问题描述】:
dictionary={'b': 5, 'a': 2, 'k': 5}
正确的输出应该是:dictionary={'b': 5, 'k': 5, 'a': 2}
使用了以下方法:
sorted(dictionary.items(), key=itemgetter(1), reverse=True)
但输出为{'k': 5, 'b': 5, 'a': 2}
edit1:我正在使用 Python 3
【问题讨论】:
-
请注意,根据您的python版本,
dicts 未排序,您可能需要使用docs.python.org/3/library/…。 -
您使用的是哪个 Python 版本?
标签: python