-1

I have this list of strings:

data = ["23444,2345,5332,2534,3229"]

Is there a way I can convert it to list of int, like this:

[23444,2345,5332,2534,3229]

3 Answers3

0

Access the first element Then split string at , and map with integer datatype it returns a lazy iterator convert it into list

data = list(map(int,data[0].split(",")))
THUNDER 07
  • 521
  • 5
  • 21
0

A simple list comprehension should do it:

data = ["23444,2345,5332,2534,3229"]
newdata = [int(v) for v in data[0].split(',')]
print(newdata)

...or with map...

newdata = list(map(int, data[0].split(',')))

Output:

[23444, 2345, 5332, 2534, 3229]
DarkKnight
  • 19,739
  • 3
  • 6
  • 22
0

Create a variable to hold your new values and simply loop through the values and convert each to int.

For example


strings = ["2","3","4","5","6"]
 ints = []

for i in strings:

    ints.append(int(i))


Maxwell D. Dorliea
  • 1,086
  • 1
  • 8
  • 20