I have a string of integers for ex. 1 2 3 4 5
. How do I convert it into a list like [1, 2, 3, 4, 5]
?
CodePudding user response:
You can do this:
int_str = '1 2 3 4 5'
int_list = list(map(int, int_str.split()))
print(int_list)
Output:
[1, 2, 3, 4, 5]