Shane Konings <shane.koni...@gmail.com> writes: > I have the following sample from a data set and I am looking to split > the address number and name into separate headings as seen below. > > FarmID Address > 1 1067 Niagara Stone > 2 4260 Mountainview > 3 25 Hunter > 4 1091 Hutchinson > 5 5172 Green Lane > 6 500 Glenridge > 7 471 Foss > 8 758 Niagara Stone > 9 3836 Main > 10 1025 York
If it is *always* the case that you just want to split the string on the first space (' ', U+0020) character, then this will do the job: >>> street_address = "1067 Niagara Stone" >>> (street_number, street_name) = street_address.split(' ', 1) >>> street_number '1067' >>> street_name 'Niagara Stone' But that's a very dubious assumption. Are you sure your data contains no examples like: PO Box 27 Unit 6, 52 Watford Avenue Lot D property 107 Sandusky Road etc.? What is your policy for dealing with data which isn't structured as you assume? -- \ “All my life I've had one dream: to achieve my many goals.” | `\ —Homer, _The Simpsons_ | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list