I am trying to pickout the words that start with vowels from given list. I am having issue when the starting letter of word is a capital vowel. I am trying below code, can anyone explain why I am not getting desired output.
JavaScript
x
7
1
l=["wood", "old", 'Apple', 'big','item', 'euphoria']
2
p=[]
3
for i in l:
4
if i[0] in('aeiou' or 'AEIOU'):
5
p.append(i)
6
print(p)
7
Advertisement
Answer
The expression ('aeiou' or 'AEIOU')
evaluates to just 'aeiou'
. Thus you end up testing for lower case vowels only. For the reason, see How do “and” and “or” act with non-boolean values?
Instead, you wanted to say
JavaScript
1
2
1
if i[0] in 'aeiou' or i[0] in 'AEIOU':
2
or
JavaScript
1
2
1
if i[0] in 'aeiouAEIOU':
2
or
JavaScript
1
2
1
if i.lower() in 'aeiou':
2