Printing list/tuple elements on separate lines

J

Johnny Chang

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', '']]
 
J

John Yeung

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:
[['asd', 'asd', 'asd', 'asd', 'asd', ''],
['asd', 'asd', 'asd', 'asd', 'asd', ''],
['asd', 'asd', 'asd', 'asd', 'asd', '']]

John
 
D

Daniel Fetchinson

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top