I’m porting some code from Python 2 to 3. This is valid code in Python 2 syntax:
def print_sorted_dictionary(dictionary):
items=dictionary.items()
items.sort()
In Python 3, the dict_items have no method ‘sort’ – how can I make a workaround for this in Python 3?
Use
items = sorted(dictionary.items()), it works great in both Python 2 and Python 3.