Skip to content

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}


See also  Convert decimal to binary in Python

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.