arrays - Python Splitting string by number and space -
hy, please me? have lot of strings contain addresses , need split them street name, house number , country in array.
something this:
streeta 15, new york street number 2 35, california streetb 36b, texas into:
['streeta','15','new york'] ['street number 2','35','california'] ['streetb','36b','texas'] thank you.
you don't need use re.compile():
import re def splitup(string): match = re.search(" \\d[^ ]*, ", string) if match none: raise valueerror("not valid string: %r" % string) street = string[:match.start()] number = string[match.start(): match.end()].strip(", ") state = string[match.end():] return [street, number, state] for examples, prints:
['streeta', '15', 'new york'] ['street number 2', '35', 'california'] ['streetb', '36b', 'texas']
Comments
Post a Comment