Answers for "how to convert string into list of int python"

14

convert list of strings to ints python

test_list = ['1', '4', '3', '6', '7'] 

int_list = [int(i) for i in test_list]
Posted by: Guest on July-02-2020
0

python string to list of int

>>> example_string = '0, 0, 0, 11, 0, 0, 0, 0, 0, 19, 0, 9, 0, 0, 0, 0, 0, 0, 11'
>>> list(map(int, example_string.split(',')))  # Python 3, in Python 2 the list() call is redundant
[0, 0, 0, 11, 0, 0, 0, 0, 0, 19, 0, 9, 0, 0, 0, 0, 0, 0, 11]
>>> [int(s) for s in example_string.split(',')]
[0, 0, 0, 11, 0, 0, 0, 0, 0, 19, 0, 9, 0, 0, 0, 0, 0, 0, 11]
Posted by: Guest on October-23-2020

Code answers related to "how to convert string into list of int python"

Python Answers by Framework

Browse Popular Code Answers by Language