I am having a list as :
>>> l = ['1', '2', '3', '4']
if I use join statement,
>>> s = ', '.join(l)
will give me output as :
'1, 2, 3, 4'
But, what I have to do If I want output as :
'1, 2, 3, 4,'
(I know that I can use string concat but I want to know some better way)
.
For str.join()
to work, the elements contained in the iterable (i.e. a list here), must be strings themselves. If you want a trailing comma, just add an empty string to the end of your list.
Edit: To flesh it out a bit:
l = map(str, [1,2,3,4])
l.append('')
s = ','.join(l)
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