Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41363

pprint defaultdict one record per line

Date 2013-03-17 12:45 -0500
Subject pprint defaultdict one record per line
From Peng Yu <pengyu.ut@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3394.1363542329.2939.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

pprint defaultdict one record per line Peng Yu <pengyu.ut@gmail.com> - 2013-03-17 12:45 -0500

csiph-web