How to Convert all Strings in a List to Int in Python
Created
Modified
Using map Method
You can convert all strings in a list to int using the map method. For example,
#!/usr/bin/python3
a = ["1", "2", "4", "5"]
b = list(map(int, a))
print(b)
[1, 2, 4, 5]
Using List Comprehension
The following example should cover whatever you are trying to do:
#!/usr/bin/python3
a = ["1", "2", "4", "5"]
b = [int(i) for i in a]
print(b)
[1, 2, 4, 5]