I have an input file containing lines like the following:
"Kansas City Chiefs 42"
Each line contains a random number of spaces between the words and the numbers. I am trying to identify a way that I can slice the two values (word portion and number portion). My ideal output would be:
"Kansas City Chiefs"
"42"
Any ideas?
Checkout this regex:
import re your_string = "Kansas City Chiefs 42" items = re.split(r's+(?=d)|(?<=d)s+', your_string) print(items)
you got:
['Kansas City Chiefs', '42']
2.1m questions
2.1m answers
60 comments
57.0k users