Separate Address number and name

Tim Chase python.list at tim.thechases.com
Tue Jan 21 22:03:42 EST 2014


On 2014-01-22 02:46, John Gordon wrote:
> > FarmID	AddressNum    AddressName
> > 1	1067          Niagara Stone
> > 2	4260          Mountainview
> > 3	25            Hunter
> > 4	1091          Hutchinson
> 
> > I have struggled with this for a while and know there must be a
> > simple method to achieve this result.
> 
> for line in input_lines:
>     fields = line.split()
>     farm_id = fields[0]
>     address_num = fields[1]
>     address_name = ' '.join(fields[2:])

Or, you can split of just the parts you need:

  for line in input_lines:
    farm_id, street_no, street_name = line.split(None, 2)

It doesn't address the issues that Ben raised about the crazy formats
you can find in addresses, but address-parsing is an twisty maze of
passages all alike.

-tkc






More information about the Python-list mailing list