3

So I am trying to format a list for this:

['w', 'e', '5', 'p', '4', '7', '2', 'w']

to this:

we5p472w

Any idea how to do this?

NOTE: this is a LIST, not a STRING

3 Answers 3

7

Use the join() method:

l = ['w', 'e', '5', 'p', '4', '7', '2', 'w']

print (''.join(l))

Outut:

we5p472w

You can use any expression to join your list elements:

print (' '.join(l))

Output:

w e 5 p 4 7 2 w
Sign up to request clarification or add additional context in comments.

Comments

2

Code:

myList = ['w', 'e', '5', 'p', '4', '7', '2', 'w']
myString = "".join(myList)
print(myString)

Output:

$ we5p472w

Comments

2
list1 = ['w', 'e', '5', 'p', '4', '7', '2', 'w']
print("".join(list1))

returns we5p472w

check https://www.geeksforgeeks.org/join-function-python/ for a more detail explanation and more examples

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.