import operator
result = sorted(dict.items(), key = operator.itemgetter(1))The type of result is "list" and is sorted by the values of dict in ascending order.
本文介绍了一种使用Python的operator模块中的itemgetter函数对字典项进行排序的方法。具体地,展示了如何将字典的项转换为列表,并按字典的值进行升序排序。
import operator
result = sorted(dict.items(), key = operator.itemgetter(1))
被折叠的 条评论
为什么被折叠?