Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Printing list/tuple elements on separate lines
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
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
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Johnny Chang  
View profile  
 More options Jun 4 2009, 8:37 pm
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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Yeung  
View profile  
 More options Jun 5 2009, 12:36 am
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:

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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Fetchinson  
View profile  
 More options Jun 5 2009, 12:44 am
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

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.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »