1

I am using the below code in python to print the values in the list in a single row, but it prints everything in a new line.

for abc in values: 
   print ','.join(abc)

Desired output:

S,t,r,e,e,t
N,o
Y,e,s
rcs
  • 6,713
  • 12
  • 53
  • 75
anand
  • 11
  • 1
  • 2

1 Answers1

0

I assume you are using python 2. If this is the case, you can add a trailing comma after your print statement:

>>> for abc in ['street','No', 'Yes']:
...     print ','.join(abc),
... 
s,t,r,e,e,t N,o Y,e,s

If you were using Python 3, you can then use the extra argument end in the print function:

>>> for abc in ['street','No', 'Yes']:
...     print(','.join(abc), end='')
... 
s,t,r,e,e,tN,oY,e,s>>> 

Note that this does not include a trailing new line.

The Python 3 method can be accomplished in Python 2 by inserting from __future__ import print_statement in the first line of your program.

TerryA
  • 58,805
  • 11
  • 114
  • 143