Professional Documents
Culture Documents
Pretty Printing
Pretty Printing
If the dictionary is large , and in order to make it presentable and readable, there is a way.
import json module (JavaScript Object Notation) and use dumps() function
syntax:
json.dumps(<dictionary name>,indent=2)
eg:
import json
employee={'name':'john','age':36,'salary':50000}
print(json.dumps(employee,indent=2))
{
"name": "john",
"age": 36,
"salary": 50000
}
{
"a": 2,
"b": 1,
"c": 3,
"d": 1
}
counting frequencies:
{
"Welcome": 1,
"to": 1,
"python": 1,
"programming": 1
}