Home > front end >  Why won't this code search if wordToList[0] is a vowel?
Why won't this code search if wordToList[0] is a vowel?

Time:10-16

def ecrypt(w):
    vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
    wordToList = list(w)
    if (wordToList[0] == vowels):
        w = w   "-way"
    return w

In this code, i'm trying to figure out if the first item in wordToList is a vowel.

CodePudding user response:

== is an equality operator. Usually used to compare objects.

To check if an item is present in a list, use the in keyword.

Example:

if (word_to_list[0] in vowels):
    print('Found a vowel')
  • Related