8. anti_vowel last o not removed


:confused: Trying this but it returns Hy lk words!. Anyone know why the last o is not removed? Can’t work it out :confused:

 def anti_vowel(text):
  lst = []
  for letter in text:

  for char in lst:
    for vowel in "aeiouAEIOU":
      if vowel == char:
  return "".join(lst)


When using .remove() the list collapses to fill the void created by removing an element. Since the pointer is moved one element to the right, it misses the element that just slipped into the previous position. That would be the second o in look.

.remove() takes the first target object it encounters, so when the o in word is reached, it removes the second o left over from look.

lst = list(text)

for char in text:
    if char in "aeiouAEIOU":

Above we iterate over text and remove items from lst. This way there is no loss of string length and the entire string is iterated.


understood, thank you!


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