Python 3 中的 Python 2 dict_items.sort()

2023-12-03

我正在将一些代码从 Python 2 移植到 3。这是 Python 2 语法中的有效代码:

def print_sorted_dictionary(dictionary):  
    items=dictionary.items()  
    items.sort()

在 Python 3 中,dict_items 没有“排序”方法 - 如何在 Python 3 中解决此问题?


Use items = sorted(dictionary.items()),它在 Python 2 中都工作得很好andPython 3.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python 3 中的 Python 2 dict_items.sort() 的相关文章

随机推荐