for i, x in enumerate(a): if i: print ',' + str(x), else: print str(x), this is a first-time switch (works for any iterable a, whether a list or otherwise) so it places the comma before each item but the first.
Embrace the future! Just to be complete, you can also do this the Python 3k way by using the print function:
from __future__ import print_function # Py 2.6+; In Py 3k not needed
mylist = ['10', 12, '14'] # Note that 12 is an int
print(*mylist,sep='\n')
Prints:
10
12
14
Eventually, print
as Python statement will go away... Might as well start to get used to it.
Use str.join
:
In [27]: mylist = ['10', '12', '14']
In [28]: print '\n'.join(mylist)
10
12
14
You can just use a simple loop: -
>>> mylist = ['10', '12', '14']
>>> for elem in mylist:
print elem
10
12
14
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With