Better create a set of vowels, for example
>>> vowels = set('aeiouAEIOU') >>> vowels set(['a', 'A', 'e', 'i', 'o', 'I', 'u', 'O', 'E', 'U'])
and then check if first one of them, like this one
>>> if first in vowels: ...
Note. A problem with
if first in 'aeiouAEIOU':
An approach
is that if your input is incorrect, for example, if first is 'ae' , then the test will fail.
>>> first = 'ae' >>> first in 'aeiouAEIOU' True
But ae clearly not a vowel.
Improvement:
If this is just a one-time job in which you do not want to create a set in advance, you can use if first in 'aeiouAEIOU': yourself, but first check the length of first , like this
>>> first = 'ae' >>> len(first) == 1 and first in 'aeiouAEIOU' False
thefourtheye
source share