Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'string': 0.09; 'character,': 0.09; 'foss': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:number': 0.09; '*always*': 0.16; '107': 0.16; 'finney': 0.16; 'headings': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'split': 0.19; 'examples': 0.20; '>>>': 0.22; 'separate': 0.22; 'header:User-Agent:1': 0.23; "i've": 0.25; 'header:X-Complaints- To:1': 0.27; 'writes:': 0.31; 'york': 0.35; 'but': 0.35; 'received:com.au': 0.36; 'unit': 0.37; 'ben': 0.38; 'to:addr :python-list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'space': 0.40; 'first': 0.61; 'address': 0.63; 'name': 0.63; 'road': 0.65; 'life': 0.66; 'sample': 0.67; '500': 0.70; 'below.': 0.71; 'hunter': 0.84; 'hutchinson': 0.84; 'received:125': 0.84; 'stone': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Ben Finney Subject: Re: Separate Address number and name Date: Wed, 22 Jan 2014 11:08:08 +1100 References: <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: vmx15867.hosting24.com.au X-Public-Key-ID: 0xBD41714B X-Public-Key-Fingerprint: 9CFE 12B0 791A 4267 887F 520C B7AC 2E51 BD41 714B X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-gpg.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Cancel-Lock: sha1:G/XJ//KMPcAySOUlIvMPUZRNC64= X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1390349308 news.xs4all.nl 2868 [2001:888:2000:d::a6]:36317 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64467 Shane Konings 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