Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephcoombe/edde3031a51da7ce8a971f0243278573 to your computer and use it in GitHub Desktop.
Save josephcoombe/edde3031a51da7ce8a971f0243278573 to your computer and use it in GitHub Desktop.
Python: Pretty print nested dictionaries
# Python: Print nested dictionaries
#
# Taken from:
# https://stackoverflow.com/a/3314411/8670609
import json
print(json.dumps({'a':2, 'b':{'x':3, 'y':{'t1': 4, 't2':5}}},
sort_keys=True, indent=4))
# {
# "a": 2,
# "b": {
# "x": 3,
# "y": {
# "t1": 4,
# "t2": 5
# }
# }
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment