[Python] How to pretty print nested dictionaries?

Discussão em 'Python' iniciado por Stack, Julho 28, 2025.

  1. Stack

    Stack Membro Participativo

    How can I pretty print a dictionary with depth of ~4 in Python? I tried pretty printing with pprint(), but it did not work:

    import pprint
    pp = pprint.PrettyPrinter(indent=4)
    pp.pprint(mydict)


    I simply want an indentation ("\t") for each nesting, so that I get something like this:

    key1
    value1
    value2
    key2
    value1
    value2


    etc.

    How can I do this?

    Continue reading...

Compartilhe esta Página