Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to sort a dictionary using pprint module in python

import pprint

a = {'c': 2, 'b': 3, 'y': 5, 'x': 10}

pp = pprint.PrettyPrinter(sort_dicts=True)
pp.pprint(a)

# Output:
# {'b': 3, 'c': 2, 'x': 10, 'y': 5}
 
PREVIOUS NEXT
Tagged: #sort #dictionary #pprint #module #python
ADD COMMENT
Topic
Name
2+8 =