Reputation: 61
I'm sorry if this is a duplicate question, but I am new to Python and not quit sure how to ask for what I need. In the most basic sense, I would like to turn this:
a = ['10', '20', '30']
Edit:
It actually:
a = [10, 20, 30]
into
a = ['102030']
Thank you so much for your help!
Upvotes: 1
Views: 1662
Reputation: 30823
The easiest will be using join with empty string:
a = ['10', '20', '30']
a = ''.join(a) #use a as result too
You will get:
'102030' #a
Edit:
Since your list is list of integer, you should "stringify" the integers first:
a = [10, 20, 30]
a = ''.join(str(x) for x in a)
or, if you want to put the single result as string to, then enclose the final result with [...]:
a = [''.join(str(x) for x in a)]
Upvotes: 1
Reputation: 951
How about,
a = ''.join(a)
a = [a] # if you want to put the string into a list
same question here: How to collapse a list into a string in python?
Upvotes: 2