Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert integers in list to string in python

I want to convert the integers from 0 to 9 to strings. I was able to do it by manually transforming each number like this:

str(1) = a
str(2) = b

... All the way untill 9. However, this is slow and the code doesn't look very pythonic. I would like to see a faster to code solution, such as putting all these numbers into a list and then transforming each element inside the list to a string. I know that to make said list I should do it like this:

a = range(0,10)

However, I don't know how to transform the ints inside the list to strings. Thanks in advance for your help.

like image 661
chilliefiber Avatar asked Oct 11 '14 23:10

chilliefiber


1 Answers

You can use map() to apply str() to each value in your array:

a = map(str, range(0, 10))
like image 149
Oleg Vaskevich Avatar answered Sep 20 '22 13:09

Oleg Vaskevich