Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41365
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'python': 0.09; '[0,': 0.09; 'collections': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'defaultdict': 0.16; 'pprint': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.17; 'import': 0.21; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'skip:# 10': 0.27; 'header:X -Complaints-To:1': 0.28; 'record': 0.28; 'cat': 0.29; 'prints': 0.29; 'subject:per': 0.29; 'from:addr:yahoo.co.uk': 0.32; 'print': 0.32; '11,': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'skip:d 20': 0.34; 'there': 0.35; 'received:org': 0.36; '12,': 0.36; 'subject:: ': 0.38; 'mark': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'subject:record': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
| Subject | Re: pprint defaultdict one record per line |
| Date | Sun, 17 Mar 2013 18:09:45 +0000 |
| References | <CABrM6wkChYLCG1AYymG=owwNNz5ivFM_h54YYs7KgZAgLyGHWw@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Gmane-NNTP-Posting-Host | host-92-18-20-125.as13285.net |
| User-Agent | Mozilla/5.0 (Windows NT 6.0; rv:17.0) Gecko/20130307 Thunderbird/17.0.4 |
| In-Reply-To | <CABrM6wkChYLCG1AYymG=owwNNz5ivFM_h54YYs7KgZAgLyGHWw@mail.gmail.com> |
| X-Antivirus | avast! (VPS 130311-2, 11/03/2013), Outbound message |
| X-Antivirus-Status | Clean |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3396.1363543729.2939.python-list@python.org> (permalink) |
| Lines | 36 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1363543729 news.xs4all.nl 6965 [2001:888:2000:d::a6]:40864 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:41365 |
Show key headers only | View raw
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