Transform String List to Integer in Python (Example Code)
In this Python tutorial you’ll learn how to transform character strings in a list object from string to integer.
Introducing Example Data
x = ['5', '1', '4', '9', '7', '2', '4', '4'] # Constructing example list print(x) # ['5', '1', '4', '9', '7', '2', '4', '4'] |
x = ['5', '1', '4', '9', '7', '2', '4', '4'] # Constructing example list print(x) # ['5', '1', '4', '9', '7', '2', '4', '4']
Example: Converting List Items from Character to Integer
x_integer = [int(i) for i in x] # Using list comprehension print(x_integer) # [5, 1, 4, 9, 7, 2, 4, 4] |
x_integer = [int(i) for i in x] # Using list comprehension print(x_integer) # [5, 1, 4, 9, 7, 2, 4, 4]
Further Resources & Related Articles
Below, you can find some further resources on topics such as character strings and data conversion.