'A' or 'An'? How to do multiple checks on vowels?



I want to change 'A' by 'An' if needed. I managed to do so, but I think there is a shorter way.

Replace this line with your code. 
fruits = ['banana', 'apple', 'orange', 'tomato', 'pear', 'grape']

print 'You have...'
for f in fruits:
    if f == 'tomato':
        print 'A tomato is not a fruit!' # (It actually is.)
    if f[0]=='a' or f[0]=='e' or f[0]=='i' or f[0]=='o' or f[0]=='u':
        print 'An', f
        print 'A', f
    print 'A fine selection of fruits!'


if f[0] in ['a', 'e', 'i', 'o', 'u']:

# or ...

vowels = ['a', 'e', 'i', 'o', 'u']

if f[0] in vowels:


vowels = ('a', 'e', 'i', 'o', 'u')

if f.startswith(vowels):

self edit:
that last one uses () instead of [] because it's a tuple.
A tuple is similar to an array, except its values can't be changed.
With a constant list (e.g., vowels) it's nice to have something like that.


Thanks, that solved the issue. I liked the intro of a 'tuple' (new to me)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.