Skip to content

Instantly share code, notes, and snippets.

@jatinkrmalik
Last active October 17, 2017 05:03
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 jatinkrmalik/cc64a3230459a83199c8b0e5806e9960 to your computer and use it in GitHub Desktop.
Save jatinkrmalik/cc64a3230459a83199c8b0e5806e9960 to your computer and use it in GitHub Desktop.
Pretty print python3 dictionary
import json
def prettyPrint(dct):
print(json.dumps(dct, indent=4, sort_keys=True))
if __name__ == "__main__":
sample = {'name':'Jatin K Malik', 'age':25, 'id':1299, 'address':'Delhi, India', 'phone':9999999999, 'hobbies':'Code'}
prettyPrint(sample)
#####################
#Output:
#{
# "address": "Delhi, India",
# "age": 25,
# "hobbies": "Code",
# "id": 1299,
# "name": "Jatin K Malik",
# "phone": 9999999999
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment