Re: Stuck on a three word street name regex

2010-01-28 Thread Brian D
On Jan 28, 8:27 am, Lie Ryan wrote: > On 01/28/10 11:28, Brian D wrote: > > > > > I've tackled this kind of problem before by looping through a patterns > > dictionary, but there must be a smarter approach. > > > Two addresses. Note that the first has incorrectly transposed the > > direction and s

Re: Stuck on a three word street name regex

2010-01-28 Thread Brian D
> Correction: > > [snip] the expression "parts[1 : -1]" means gather list items from the > second element in the list (index value 1) to one index position > before the end of the list. [snip] MRAB's solution was deserving of a more complete solution: >>> def parse_address(address): # Ha

Re: Stuck on a three word street name regex

2010-01-28 Thread Lie Ryan
On 01/28/10 11:28, Brian D wrote: > I've tackled this kind of problem before by looping through a patterns > dictionary, but there must be a smarter approach. > > Two addresses. Note that the first has incorrectly transposed the > direction and street name. The second has an extra space in it befo

Re: Stuck on a three word street name regex

2010-01-28 Thread Brian D
On Jan 28, 7:40 am, Brian D wrote: > > > [snip] > > > Regex doesn't gain you much. I'd split the string and then fix the parts > > > as necessary: > > > >  >>> def parse_address(address): > > > ...     parts = address.split() > > > ...     if parts[-2] == "S": > > > ...         parts[1 : -1] = [pa

Re: Stuck on a three word street name regex

2010-01-28 Thread Brian D
> > [snip] > > Regex doesn't gain you much. I'd split the string and then fix the parts > > as necessary: > > >  >>> def parse_address(address): > > ...     parts = address.split() > > ...     if parts[-2] == "S": > > ...         parts[1 : -1] = [parts[-2]] + parts[1 : -2] > > ...     parts[1 : -1]

Re: Stuck on a three word street name regex

2010-01-27 Thread Brian D
On Jan 27, 7:27 pm, MRAB wrote: > Brian D wrote: > > I've tackled this kind of problem before by looping through a patterns > > dictionary, but there must be a smarter approach. > > > Two addresses. Note that the first has incorrectly transposed the > > direction and street name. The second has an

Re: Stuck on a three word street name regex

2010-01-27 Thread Brian D
On Jan 27, 6:35 pm, Paul Rubin wrote: > Brian D writes: > > I've tackled this kind of problem before by looping through a patterns > > dictionary, but there must be a smarter approach.> > > Two addresses. Note that the first has incorrectly transposed the > > direction and street name. > > I

Re: Stuck on a three word street name regex

2010-01-27 Thread MRAB
Brian D wrote: I've tackled this kind of problem before by looping through a patterns dictionary, but there must be a smarter approach. Two addresses. Note that the first has incorrectly transposed the direction and street name. The second has an extra space in it before the street type. Clearly

Re: Stuck on a three word street name regex

2010-01-27 Thread Paul Rubin
Brian D writes: > I've tackled this kind of problem before by looping through a patterns > dictionary, but there must be a smarter approach.> > Two addresses. Note that the first has incorrectly transposed the > direction and street name. If you're really serious about it (e.g. you are the p