I have an array like this type ["1" "2" "3"]
, how can I change this into a list [1, 2, 3]
Could some one please help me regarding this?
Asked
Active
Viewed 3,065 times
1

Felix Kling
- 795,719
- 175
- 1,089
- 1,143

Priya
- 69
- 2
- 8
3 Answers
1
Both ["1", "2", "3"]
and [1, 2, 3]
are lists. The former is just a list of strings, whereas the latter is a list of integers. Call int
on every element to convert it to an integer, like this:
str_list = ["1", "2", "3"]
int_list = [int(e) for e in str_list]
# or ...
int_list = map(int, str_list)

phihag
- 278,196
- 72
- 453
- 469
0
If your array is really ["1" "2" "3"], it will be concatenated into a single string like such ["123"] so you'll need split the string like so:
newList = []
for n in xrange(len(oldList[0])):
newList.append(int(oldList[0][n]))

user1012037
- 501
- 1
- 4
- 18