Printing list/tuple elements on separate lines

John Yeung gallium.arsenide at gmail.com
Fri Jun 5 06:36:05 CEST 2009


On Jun 4, 8:37 pm, Johnny Chang <johnny... at 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



More information about the Python-list mailing list