Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subject:error': 0.03; 'iterate': 0.09; 'logic': 0.09; 'prefix': 0.09; 'sentence': 0.09; 'def': 0.12; 'cleaner': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'index.': 0.16; 'optionally': 0.16; 'stem': 0.16; 'index': 0.16; 'wrote:': 0.18; 'input': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'header :In-Reply-To:1': 0.27; "doesn't": 0.30; 'getting': 0.31; 'index,': 0.31; 'figure': 0.32; 'something': 0.35; 'test': 0.35; 'so,': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'little': 0.38; 'itself': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'letters': 0.60; 'solve': 0.60; 'break': 0.61; 'happen': 0.63; 'subject:This': 0.74; 'idiom': 0.84; 'subject:interesting': 0.84; 'directly.': 0.95 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Sun, 31 Aug 2014 16:10:27 -0600 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11 MIME-Version: 1.0 To: python-list@python.org Subject: Re: This could be an interesting error References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit 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: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409523047 news.xs4all.nl 2906 [2001:888:2000:d::a6]:33265 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77364 On 08/31/2014 03:02 PM, Seymore4Head wrote: > def pigword(test): > for x in range(len(test)): > if test[x] in "AEIOUaeiou": > stem = test [x:] > prefix = test [:x] > pigword = stem + prefix + "ay" > print ("Stem ",stem) > print ("Prefix",prefix) > print (pigword) > break > return (pigword) So, what do you think will happen if the word contains no vowels? Where is pigword defined? > for x in range(len(newex)): > sentence = sentence + pigword(newex[x])+ " " > print (sentence) > wait = input (" Wait") You don't need to iterate over range(len(blah)). The standard idiom when you need index as well as the item itself is to iterate over enumerate(). Or if you don't need the index, just iterate directly. You can iterate directly over the list, or the letters in the word, optionally getting an index. It's much cleaner and less error prone. Consider something like: def pigword(word): for x,letter in enumerate(word): # x is index (position), letter is the value at that index if letter in "AEIOUaeiou": ... for word in list_of_words: sentence = sentence + pigword(word) + " " ... That doesn't solve your little logic problem, though I think you can figure that part out easily!