I have a string "12 21 3 9 21 19" and I would like to split it up into a list [12, 21, 3, 9, 21, 19].
Doing newlist = list("12 21 3 9 21 19") breaks it up to [1,2,2,1,3,9,2,1,1,9]! Any help would be greatly appreciated :)
I have a string "12 21 3 9 21 19" and I would like to split it up into a list [12, 21, 3, 9, 21, 19].
Doing newlist = list("12 21 3 9 21 19") breaks it up to [1,2,2,1,3,9,2,1,1,9]! Any help would be greatly appreciated :)
You can use .split()
e.g. -
>>> my_string = "12 21 3 9 21 19"
>>> a_new_list = my_string.split()
>>> print(a_new_list)
>>> ["12", "21", "3", "9", "21", "19"]
If you wanted the actual members of the list to be int
s you could convert them to integers using map or some other method.