1

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!

4 Answers 4

2

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?

Sign up to request clarification or add additional context in comments.

Comments

1

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)]

12 Comments

It doesn't seem to be working. The elements in my list don't have single quotes around each integer. Does this matter?
It does matter. That means you have list of integer not list of string, is it?
Oh, how can I change it?
Now I see! Thanks so much Ian!
So how can I then make that string into a simple number value for a variable? Sorry for the lack of Python terms...
|
0

Try this:

a = ['10', '20', '30']

print [''.join(a)]

Comments

0

Late answer after edit:

[''.join(map(str, a))] # ['102030']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.