我正在将一些代码从Python 2移植到3.这是Python 2语法中的有效代码:
def print_sorted_dictionary(dictionary):
items=dictionary.items()
items.sort()
Run Code Online (Sandbox Code Playgroud)
在Python 3中,dict_items没有方法'sort' - 我如何在Python 3中为此做出解决方法?
使用items = sorted(dictionary.items()),它在Python 2 和 Python 3 中都很有用.