Reputation: 21
so I'm trying to split a string like "19 01 23 75 03 34" into an array. Normally I would use list() and then just strip the spaces, but because these are two digit numbers, that separates them into one digit numbers. I'm still new to python, so sorry if there's a really easy answer to this! Thanks for your help.
Upvotes: 1
Views: 2905
Reputation: 838336
Use str.split
:
numbers = "19 01 23 75 03 34".split()
If you also want to parse them to integers you can use map
and int
:
numbers = map(int, "19 01 23 75 03 34".split())
See it working online: ideone
Upvotes: 4