Printing list/tuple elements on separate lines
The group you are posting to is a
Usenet group . Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Newsgroups: comp.lang.python
From:
Johnny Chang <johnny... @gmail.com>
Date: Thu, 4 Jun 2009 17:37:42 -0700 (PDT)
Local: Thurs, Jun 4 2009 8:37 pm
Subject: Printing list/tuple elements on separate lines
I have a large list of strings that I am unpacking and splitting, and I want each one to be on a new line. Someone showed me how to do it and I got it working, except it is not printing each on its own separate line as his did, making it incredibly hard to read. He did it without adding a new line for anything. I can't get in touch with him right now. An example:
recs = 'asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf' [(rec.split('f')) for rec in recs]
output:
[['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', '']]
desired output:
[['asd', 'asd', 'asd', 'asd', 'asd', ''] ['asd', 'asd', 'asd', 'asd', 'asd', ''] ['asd', 'asd', 'asd', 'asd', 'asd', '']]
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.python
From:
John Yeung <gallium.arsen... @gmail.com>
Date: Thu, 4 Jun 2009 21:36:05 -0700 (PDT)
Local: Fri, Jun 5 2009 12:36 am
Subject: Re: Printing list/tuple elements on separate lines
On Jun 4, 8:37 pm, Johnny Chang <johnny... @gmail.com> wrote:
> I have a large list of strings that I am unpacking
> and splitting, and I want each one to be on a new line.
> An example:
> recs = > 'asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf' > [(rec.split('f')) for rec in recs]
> output:
> [['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', > 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', '']]
> desired output:
> [['asd', 'asd', 'asd', 'asd', 'asd', ''] > ['asd', 'asd', 'asd', 'asd', 'asd', ''] > ['asd', 'asd', 'asd', 'asd', 'asd', '']]
Your friend may have used pprint:
>>> from pprint import pprint >>> pprint(recs)
[['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', '']] John
You must
Sign in before you can post messages.
You do not have the permission required to post.
Newsgroups: comp.lang.python
From:
Daniel Fetchinson <fetchin... @googlemail.com>
Date: Thu, 4 Jun 2009 21:44:07 -0700
Local: Fri, Jun 5 2009 12:44 am
Subject: Re: Printing list/tuple elements on separate lines
>> I have a large list of strings that I am unpacking
>> and splitting, and I want each one to be on a new line.
>> An example:
>> recs = >> 'asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf','asdfasdfasdfasdfasdf' >> [(rec.split('f')) for rec in recs]
>> output:
>> [['asd', 'asd', 'asd', 'asd', 'asd', ''], ['asd', 'asd', 'asd', 'asd', >> 'asd', ''], ['asd', 'asd', 'asd', 'asd', 'asd', '']]
>> desired output:
>> [['asd', 'asd', 'asd', 'asd', 'asd', ''] >> ['asd', 'asd', 'asd', 'asd', 'asd', ''] >> ['asd', 'asd', 'asd', 'asd', 'asd', '']]
By slightly modifying your requirements this might be good too: print '\n'.join( [ 'aaaaaa', 'bbbbbbb', 'cccccccc', 'dddddddd', 'eeeeeeee' ] )
Cheers, Daniel
-- Psss, psss, put it down! - http://www.cafepress.com/putitdown
You must
Sign in before you can post messages.
You do not have the permission required to post.