Sort a dictionary by key in Python
Advertisements
dictionary = {'one': 1, 'three': 3, 'five': 5, 'two': 2, 'four': 4} print(dict(sorted(dictionary.items(), reverse = False))) #{'four': 4, 'five': 5, 'three': 3, 'two': 2, 'one': 1}