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]
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]
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(",")))
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]
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))