I am trying to form a string using a list.
If the list only has a single element e.g. l = [10]
then the string should be 10
.
If there are multiple elements e.g. l = [10,20,30]
then the string should be 10,20,30
.
I tried but it always appends extra ,
at the end.
"".join("%s," % x for x in l)
This produces 10,
and 10,20,30,
for the above lists.
Just use the following:
','.join(str(n) for n in l)
Here's my solution. I do not know if it satisfies your
str(l)[1:-1]
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