Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41365
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Subject | Re: pprint defaultdict one record per line |
| Date | 2013-03-17 18:09 +0000 |
| References | <CABrM6wkChYLCG1AYymG=owwNNz5ivFM_h54YYs7KgZAgLyGHWw@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3396.1363543729.2939.python-list@python.org> (permalink) |
On 17/03/2013 17:45, Peng Yu wrote:
> 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)
>
Try writing a for loop that prints one record per line.
--
Cheers.
Mark Lawrence
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: pprint defaultdict one record per line Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-03-17 18:09 +0000
csiph-web