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


Groups > comp.lang.python > #41363 > unrolled thread

pprint defaultdict one record per line

Started byPeng Yu <pengyu.ut@gmail.com>
First post2013-03-17 12:45 -0500
Last post2013-03-17 12:45 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

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

#41363 — pprint defaultdict one record per line

FromPeng Yu <pengyu.ut@gmail.com>
Date2013-03-17 12:45 -0500
Subjectpprint defaultdict one record per line
Message-ID<mailman.3394.1363542329.2939.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web