Python good programming practice for enumerating lists
list, python
Solution
No it is not considered good practice, there are always better ways :D
if i.upper() in "AEIOU"
Here is a much shorter version of your function using list comprehensions:
def get_vowels(word):
vowels = "AEIOU"
return [c for c in word if c.upper() in vowels]
Problem
I'm pretty new to Python and programming in general, and I was wondering if it is a good programming practice to write long statements with many logic operators - for example, in a for loop. For example, here's a function I made that gets all the vowels from a word and returns a list containing those vowels. ``` def getVowels(word): vowel_list = [] index = 0 for i in word: if i == "a" or i == "e" or i == "i" or i == "o" or i == "u" or i == "A" or i == "E" or i == "I" or i == "O" or i == "U": vowel_list.append(word[index]) index += 1 return vowel_list ``` As you can see, the if statement has gotten very long. Is it considered good programming? If it's not, is there a better way to code this function?