How to iterate throuhg dictionary

François Pinard pinard at iro.umontreal.ca
Wed Aug 8 17:19:09 CEST 2001


> François Pinard wrote:

> > It is often nice to do:
> >         import pprint
> >         pprint.pprint(d)

[Mark Robinson]

> I just had a quick play with that, and I can't see any difference between
> your example verbatum and simply print d.

Oh, then your `d' should be simple.  `pprint.pprint' would print long or
complex structures on multiple lines, all nicely indented.  Dictionaries
entries are shown sorted by key.  I find it so useful that I forever had:

    import pprint
    pp = pprint.pprint

in my `.pythonrc' filean I could use thinks like `pp(d)' interactively.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard




More information about the Python-list mailing list