Split the string when alphabet is found next to a number using regex Python -
i have string this
string = "3,197working age population"
i want break string such when number 3,197 ends , working age population starts using regex or other efficient method. in short need 3,197
you may have @ itertools.takewhile
:
from itertools import takewhile string = "3,197working age population" r = ''.join(takewhile(lambda x: not x.isalpha(), string)) print(r) # '3,197'
takes items string while alphabet has not been reached. result reformed string using join
Comments
Post a Comment