Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strip everything until any number (0-9) is reached?

How can I strip everything leading up to a number? Of course this would have to work for any number, not just 1.

I would like blahblahblah 1 main street as input. And 1 main street as output.

like image 989
Harrison Avatar asked Oct 25 '25 01:10

Harrison


1 Answers

You can use itertools.dropwhile. Drops everthing before a '1' (or any other number) is reached:

from itertools import dropwhile

s = 'blahblahblah 1 main street'
r = ''.join(dropwhile(lambda x: not x.isdigit(), s))

print(r)
# '1 main street'

Works with all numbers

like image 98
Moses Koledoye Avatar answered Oct 27 '25 17:10

Moses Koledoye