0

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.

l=["wood", "old", 'Apple', 'big','item', 'euphoria']
p=[]
for i in l:
    if i[0] in('aeiou' or 'AEIOU'):
        p.append(i)
print(p)
Babu
  • 9
  • 2

2 Answers2

1

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

if i[0] in 'aeiou' or i[0] in 'AEIOU':

or

if i[0] in 'aeiouAEIOU':

or

if i.lower() in 'aeiou':
Jussi Nurminen
  • 2,257
  • 1
  • 9
  • 16
0

it may be easier to use lower() like so

l=["wood", "old", 'Apple', 'big','item', 'euphoria']
p=[]
for i in l:
    if i[0].lower() in('aeiou'):
        p.append(i)
print(p)

Output:

['old', 'Apple', 'item', 'euphoria']
Patrick
  • 1,189
  • 5
  • 11
  • 19