1

I'm trying to take a list of words and print out another list of every word that has all 5 written vowels 'aeiou'.

print([word for word in word_list if 'a' in word and 'e' in word and 'i' in word and 'o' in word and 'u' in 
word])

For example, 'equation', 'consequential', and 'authorize' would be in the output list.

How can I consolidate all the conditions in the if-statement?

asked May 16, 2020 at 6:00
0

1 Answer 1

1

This works :

print([word for word in word_list if all(letter in word for letter in "aeiou")])

Test live example on onlinegdb.

Basically, the conditions follow a pattern so you can factorize them in a test "for each character in the string 'aeiou', test if character is in main string" .

all(conditions) is to be used since you want all of them to be true at the same time, because of and (for or you could use any instead of all)

answered May 16, 2020 at 6:08
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.