Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: convert each element to string in a list, without using for loop

Tags:

python

for solving above problem I normally use for loop like that:

list1 = ['1', '2', 3,32423,5.76, "afef"]
list2 = []
for ele in list1:
  list2.append(str(ele))

does python has some build in function for solving that problem?

like image 513
Sway Wu Avatar asked Oct 23 '25 23:10

Sway Wu


1 Answers

You can use the built-in function map like the following:

list1 = ['1', '2', 3, 32423, 5.76, "afef"]
list2 = list(map(str, list1))
like image 127
Gorisanson Avatar answered Oct 25 '25 13:10

Gorisanson