pprint defaultdict one record per line


P

Peng Yu

Hi,

pprint can not print defaultdict one record per line. Is there some
other convenient way in python to print one record per line?

~/linux/test/python/man/library/pprint/function/pprint$ ./main.py
{'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], 'one': [0,
1, 2, 3, 4, 5, 6, 7, 8, 9]}
{'one': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]}
defaultdict(<type 'list'>, {'two': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14], 'one': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]})
~/linux/test/python/man/library/pprint/function/pprint$ cat main.py
#!/usr/bin/env python

import pprint

d=dict(one=range(10), two=range(15))
print d
pprint.pprint(d)

from collections import defaultdict
d=defaultdict(list)
d['one']=range(10)
d['two']=range(15)
pprint.pprint(d)
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top