Anti_vowel (8/15)


#1

Hello, my code for this lesson seems to be misbehaving.

def anti_vowel(text):
  string = list(text)
  for c in string:
    if c in "aeiouAEIOU":
      string.remove(c)
  string = ''.join(string)
  return string
print anti_vowel('Hey Look Words!')

This is my code, it works normally for ‘Hey’ and ‘Look’, removing the vowels as intended. When it gets to ‘Words’ though, it does not remove the ‘o’. I can’t really think of a reson why this would happen. Any insight would be great.
Thank you!


#2

You’re looping through it while also removing from it. Kind of like pulling a rug from under the loop.
Also note that each removal from a list iterates through the whole list (inefficient)


#3

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