Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.05; 'assignment': 0.07; 'indexing': 0.07; 'imho.': 0.09; 'lost.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'throw': 0.09; 'python': 0.10; 'index': 0.13; 'times,': 0.13; 'do,': 0.15; 'thu,': 0.15; 'indexerror:': 0.16; 'input.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:assistance': 0.16; 'wrote:': 0.16; 'string': 0.17; 'input': 0.18; 'language': 0.19; '>>>': 0.20; '2015': 0.20; 'first,': 0.20; '"",': 0.22; 'lawrence': 0.22; 'space.': 0.22; 'trying': 0.22; 'code,': 0.23; 'code.': 0.23; 'bit': 0.23; 'daniel': 0.23; 'minutes.': 0.23; 'split': 0.23; "haven't": 0.24; 'tried': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'appreciated.': 0.27; 'figure': 0.27; 'mostly': 0.27; 'order.': 0.27; 'least': 0.27; 'correct': 0.28; 'function': 0.28; '-0700,': 0.29; 'index,': 0.29; 'spaces': 0.29; "i'm": 0.30; 'certainly': 0.30; "can't": 0.32; 'language.': 0.32; 'problem': 0.33; 'url:python': 0.33; 'traceback': 0.33; "i'll": 0.33; 'file': 0.34; 'next': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'display': 0.37; 'received:org': 0.37; 'difference': 0.38; 'to:addr:python.org': 0.40; 'mark': 0.40; 'url:3': 0.60; 'care': 0.60; 'your': 0.60; "you'll": 0.61; 'subject:Need': 0.61; 'back': 0.62; 'charset:windows-1252': 0.62; 'spot': 0.63; 'our': 0.64; 'between': 0.65; 'incorporate': 0.66; 'jul': 0.72; 'gotten': 0.76; 'about,': 0.84; 'feet.': 0.84; 'hammer': 0.84; 'homework': 0.84; 'pythonistas,': 0.84; 'inefficient': 0.91; 'mean.': 0.91; 'forever.': 0.93; 'hand,': 0.97 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Need assistance Date: Fri, 17 Jul 2015 20:00:43 +0100 References: <225d4ac6-3b88-4844-805b-b4b00cd62ef4@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-180-93.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 66 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1437159662 news.xs4all.nl 2831 [2001:888:2000:d::a6]:47525 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:94025 On 17/07/2015 17:40, Rob Gaddi wrote: > On Thu, 16 Jul 2015 19:15:38 -0700, craig.sirna wrote: > >> I need help writing a homework program. >> >> I'll write it, but I can't figure out how to incorporate what I have >> read in the book to work in code. >> >> The assignment wants us to take a users first, middle and last name in a >> single input ( name=('enter your full name: )). >> >> Then we must display the full name rearranged in Last, First Middle >> order. >> >> I tried to use the search function in Python to locate any spaces in the >> input. It spot back the index 5 (I used Craig Daniel Sirna) >> >> That is correct for the first space, but I can't figure out how to get >> it to continue to the next space. >> >> The indexing process is also a bit confusingto me. >> >> I get that I can use len(fullName) to set the length of the index, and >> how the index is counted, but after that I'm lost. >> >> I have emailed my professor a few times, but haven't gotten a >> response.(online course) >> >> Any help would be greatly appreciated. > > 1) Use the interactive console. Set x = 'Craig Daniel Sirna' and play > with indexing and slicing it until you really internalize what they > mean. x[3], x[-3], x[0:10], x[0:-1]. It's not actually relevant to the > problem at hand, but right now is the time in your education to get > indexing down cold; skimp on it now and you'll pay for it forever. > Should take you about 5 minutes. I'll throw in something to emphasize a major difference between indexing and slicing. >>> x = 'Craig Daniel Sirna' >>> x[100] Traceback (most recent call last): File "", line 1, in IndexError: string index out of range >>> x[100:] '' >>> x[:100] 'Craig Daniel Sirna' > > 2) https://docs.python.org/3/library/stdtypes.html#string-methods > You can do what you're trying to do, but you're swinging a hammer with a > powered nailgun at your feet. Search is an inefficient way to try to > split a string into parts based on a delimiter. > Inefficient I don't know about, and mostly don't care about either, but certainly not the cleanest way to code, at least IMHO. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence