Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.