Python | Pretty Print a dictionary with dictionary value
This article just provides a quick way to pretty print a dictionary which has dictionary as values. This is required many times now days as the advent of NoSQL databases. Lets code a way to perform this particular task.
Method : Using loops
We just loop through each dictionary element and it’s corresponding values using brute manner of loops.
# Python3 code to demonstrate working of # Pretty Print a dictionary with dictionary value # Using loops # initializing dictionary test_dict = {'gfg' : {'rate' : 5, 'remark' : 'good'}, 'cs' : {'rate' : 3}} # printing original dictionary print("The original dictionary is : " + str(test_dict)) # using loops to Pretty Print print("The Pretty Print dictionary is : ") for sub in test_dict: print (sub) for sub_nest in test_dict[sub]: print (sub_nest, ':', test_dict[sub][sub_nest]) |
chevron_right
filter_none
Output :
The original dictionary is : {'gfg': {'remark': 'good', 'rate': 5}, 'cs': {'rate': 3}}
The Pretty Print dictionary is :
gfg
remark : good
rate : 5
cs
rate : 3
Recommended Posts:
- Python | Convert flattened dictionary into nested dictionary
- Python | Convert nested dictionary into flattened dictionary
- Python | Convert string dictionary to dictionary
- Print anagrams together in Python using List and Dictionary
- Program to print all distinct elements of a given integer array in Python | Ordered Dictionary
- Python Dictionary
- Python | Get key from value in Dictionary
- Python | Get the first key in dictionary
- Python | Transcribing dictionary key
- Python | Dictionary has_key()
- Python | Convert a set into dictionary
- Second largest value in a Python Dictionary
- Few mistakes when using Python dictionary
- Python | Check if key has Non-None value in dictionary
- Python Dictionary | pop() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


