Printing list/tuple elements on separate lines

Discussion in 'Python' started by Johnny Chang, Jun 5, 2009.

  1. Johnny Chang

    Johnny Chang Guest

    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', '']]
     
    Johnny Chang, Jun 5, 2009
    #1
    1. Advertising

  2. Johnny Chang

    John Yeung Guest

    On Jun 4, 8:37 pm, Johnny Chang <> 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
     
    John Yeung, Jun 5, 2009
    #2
    1. Advertising

  3. >> 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
     
    Daniel Fetchinson, Jun 5, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Mikolajczyk
    Replies:
    1
    Views:
    841
    Larry Bates
    Apr 20, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    1,052
    Jeff Epler
    Apr 20, 2004
  3. Davy
    Replies:
    3
    Views:
    1,917
    Wildemar Wildenburger
    Nov 7, 2007
  4. Jeff Nyman
    Replies:
    8
    Views:
    404
    Terry Reedy
    Jun 5, 2008
  5. Ciba LO
    Replies:
    4
    Views:
    202
    Ciba LO
    Jul 8, 2006
Loading...

Share This Page