Skip to content

Latest commit

 

History

History
32 lines (26 loc) · 712 Bytes

print-a-python-dict-nicely.md

File metadata and controls

32 lines (26 loc) · 712 Bytes
author category date summary title
Python
2019-07-12
Print A Python Dict Nicely

Print a python dict nicely

You could use pprint but json.dumps is much better

my_dict = {'hello': [{'chops': 'chaps', 'trash': 4456}, {'chats': 'chops'}, True]}

import json
print(json.dumps(my_dict, indent=4, sort_keys=True))  

{
    "hello": [
        {
            "chops": "chaps",
            "trash": 4456
        },
        {
            "chats": "chops"
        },
        true
    ]
}

Source