This could be an interesting error

Michael Torrie torriem at gmail.com
Mon Sep 1 00:52:13 EDT 2014


On 08/31/2014 10:15 PM, Michael Torrie wrote:
> On 08/31/2014 06:04 PM, Seymore4Head wrote:
>>>    for x,letter in enumerate(word):
>>>        # x is index (position), letter is the value at that index
>>>        if letter in "AEIOUaeiou":
>> I tried changing:
>> for x in range(len(test)):
>> to
>> for x in enumerate(test):
> 
> Read my example again. You missed something vital.  enumerate returns
> both a position and the item:
> 

Sigh.  Oops.  Make that:

for x,letter in enumerate("hello"):
    print (x, " ", letter)

You definitely should start doing it this way.  It's more "pythonic" and
also cleaner and easier to understand when you're reading the code later.

Also you did add Y to your list of vowels, but what about words that
have no vowels and no Y?  Maybe not real words, but things that might be
likely to be in sentences:  "I am from Washington, DC"

It's way better to fix your logic so you have a fall-back.  Hint: Set
pigword before your enter the loop so that it always contains
_something_, preferably the original word!



More information about the Python-list mailing list