Split long string of addresses into list of addresses in Python
Question: I have a string of a couple thousand addresses in python, like such:

`'123 Chestnut Way 4567 Oak Lane 890 South Pine Court'`

What is the easiest way to split this long string into separate addresses? I'm
trying to write a program that splits based on 3 or 4 characters in a row
where `47 < ord(i) < 58`, but I'm having trouble.


Answer: Assuming all of the addresses are like those given, you can use
[`re.findall`](https://docs.python.org/2/library/re.html#re.findall):

    
    
    >>> from re import findall
    >>> string = '123 Chestnut Way 4567 Oak Lane 890 South Pine Court'
    >>> findall("\d+\D+(?=\s\d|$)", string)
    ['123 Chestnut Way', '4567 Oak Lane', '890 South Pine Court']
    >>>
    

All of the Regex syntax used above is explained
[here](https://docs.python.org/2/library/re.html#regular-expression-syntax),
but below is a quick breakdown:

    
    
    \d+   # One or more digits
    \D+   # One or more non-digits
    (?=   # The start of a lookahead assertion
    \s    # A space
    \d|$  # A digit or the end of the string
    )     # The end of the lookahead assertion
    

