{"id":5516,"date":"2023-10-27T11:53:54","date_gmt":"2023-10-27T06:23:54","guid":{"rendered":"https:\/\/python-programs.com\/?p=5516"},"modified":"2023-11-10T12:03:11","modified_gmt":"2023-11-10T06:33:11","slug":"python-pretty-print-nested-dictionaries-dict-of-dicts","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-pretty-print-nested-dictionaries-dict-of-dicts\/","title":{"rendered":"Python: Pretty Print Nested Dictionaries \u2013 Dict of Dicts"},"content":{"rendered":"

Dictionaries are Python\u2019s implementation of an associative list, which\u00a0may be a\u00a0<\/span>arrangement\u00a0<\/span>. A dictionary\u00a0may be a\u00a0<\/span>collection of key-value pairs that are stored together. A key and its value are represented by each key-value pair.<\/p>\n

To an infinite depth, a dictionary may include another dictionary, which can contain dictionaries, and so on. This is referred to as a nested dictionary.<\/p>\n

Nested dictionaries are\u00a0one among\u00a0<\/span>several ways\u00a0during which\u00a0<\/span>structured information is represented (similar to records or structures in other languages).<\/p>\n

In this article, we’ll look at how to print a nested dictionary in a visually beautiful and readable format.<\/p>\n

Examples:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

nesteddict = {\r\n'hello': {'www': 100, 'yyy': 'Helloworld'},\r\n'this': {'www': 'vikram', 'age': 20, 'DOB': 'FEB'},\r\n'BTechGeeks': {'PLACE': 'HYDERABAD', 'PINCODE': 500000,\r\n'PYTHON': {'FUNCTIONS': 'Built in', 'year': 1999}},\r\n}<\/pre>\n

Output:<\/strong><\/p>\n

{\r\n    \"hello\": {\r\n        \"www\": 100,\r\n        \"yyy\": \"Helloworld\"\r\n    },\r\n    \"this\": {\r\n        \"www\": \"vikram\",\r\n        \"age\": 20,\r\n        \"DOB\": \"FEB\"\r\n    },\r\n    \"BTechGeeks\": {\r\n        \"PLACE\": \"HYDERABAD\",\r\n        \"PINCODE\": 500000,\r\n        \"PYTHON\": {\r\n            \"FUNCTIONS\": \"Built in\",\r\n            \"year\": 1999\r\n        }\r\n    }\r\n}<\/pre>\n

Print nested dictionaries in pretty way<\/h2>\n

There are several ways to print nested dictionaries in pretty way some of them are:<\/p>\n