Function to Print a nicely formatted Dictionary or List?

Michael F. Stemper michael.stemper at gmail.com
Thu Jun 9 15:49:36 EDT 2022


On 09/06/2022 12.52, Chris Angelico wrote:
> On Fri, 10 Jun 2022 at 03:44, Dave <dave at looktowindward.com> wrote:

>> Before I write my own I wondering if anyone knows of a function that will print a nicely formatted dictionary?
>>
>> By nicely formatted I mean not all on one line!
>>
> 
> https://docs.python.org/3/library/pprint.html
> 
> from pprint import pprint
> pprint(thing)

  >>> from pprint import pprint
  >>> d = {'two':2, 'three':5}
  >>> pprint(d)
  {'three': 5, 'two': 2}
  >>>

This is all on one line. That might be acceptable to the OP, but it
doesn't actually match what he said.

-- 
Michael F. Stemper
Outside of a dog, a book is man's best friend.
Inside of a dog, it's too dark to read.


More information about the Python-list mailing list