0

How should I convert list elements to string using Python?

For example I have a list that looks like this:

[1, 2, 3, 4, 5] 

And I want it to look like this:

['1', '2', '3', '4', '5'] 
2
  • lst=list(map(str, lst)) where lst is your input list Commented Jul 2, 2020 at 12:40
  • 1
    Please add a sample input and expected output. This question is very vague. Take a look at writing minimal reproducible example Commented Jul 2, 2020 at 12:44

2 Answers 2

1

Use a one-liner to iterate over all elements it an Iterable and use str(element) to cast the element as a string

new_list = [str(i) for i in old_list] 
Sign up to request clarification or add additional context in comments.

Comments

0
def listToString(a): li = [] for i in a: li.append(str(i)) return li 

We can input the list in the function.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.