8. anti_vowel


#1

def anti_vowel(text):

word = []
avword = []
length = len(text)
vowels = [“a”, “A”, “e”, “E”, “i”, “I”, “o”, “O”, “u”, “U”]
for letters in text:
word.append(letters)
for letter in word:
if letter in vowels:
word.remove(letter)
else:
avword.append(letter)
“”.join(avword)
return avword
print anti_vowel(“Hey look Words!”)

Your function fails on anti_vowel(“Hey look Words!”). It returns “[‘H’, ’ ', ‘l’, ‘k’, ’ ', ‘W’, ‘d’, ‘s’, ‘!’]” when it should return “Hy lk Wrds!”.

My function for some reason gets rid of the “y” in “Hey” and the “r” in “Words” even though they aren’t vowels and the .join syntax isnt working


#2

Update:
I changed some stuff in my function and now it returns “Hy” instead of “H” but now its returning “Words” instead of how its supposed to return “Wrds”

def anti_vowel(text):  
  word = []
  length = len(text)
  vowels = ["a", "A", "e", "E", "i", "I", "o", "O", "u", "U"]  
  for letters in text:
    word.append(letters)
  for letter in word:
    if letter in vowels:
      word.remove(letter)
  "".join(word)
  return word
print anti_vowel("Hey look Words!")

Your function fails on anti_vowel(“Hey look Words!”). It returns “[‘H’, ‘y’, ’ ', ‘l’, ‘k’, ’ ', ‘W’, ‘o’, ‘r’, ‘d’, ‘s’, ‘!’]” when it should return “Hy lk Wrds!”.


#3

When we remove an item from a list that we are iterating, it can mess things up since content after that point is shifted left. That places the next item to be iterated in the slot before it, so it gets skipped.

The join line is not doing anything. Combine the two…

return ''.join(word)

#4

Thanks for the fast reply :slight_smile:


#5

I’m still a bit confused because with what you said, shouldn’t it return “Hy lok Wrds!” because of the two Os in “look”? Instead it returns “Hy lk Words”. That o in “Words” is also not going away.

def anti_vowel(text):
word = []
length = len(text)
vowels = [“a”, “A”, “e”, “E”, “i”, “I”, “o”, “O”, “u”, “U”]
for letters in text:
word.append(letters)
for letter in word:
if letter in vowels:
word.remove(letter)
return “”.join(word)
print anti_vowel(“Hey look Words!”)

Your function fails on anti_vowel(“Hey look Words!”). It returns “Hy lk Words!” when it should return “Hy lk Wrds!”.


#6

The code still removes from the oterab;e.


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.