pprint defaultdict one record per line

Peng Yu pengyu.ut at gmail.com
Sun Mar 17 13:45:26 EDT 2013


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)

-- 
Regards,
Peng



More information about the Python-list mailing list