8/15 anti_vowel: Practice Makes Perfect


This is my code right now:

def anti_vowel(text):
lizt = list(text)
for letter in lizt:
if letter in 'aeiouAEIOU':
finaltext = ''.join(lizt)
return finaltext

It throws an error telling my code returned "Hy lk Words" instead of "Hy lk Wrds".
Can someone help me?


@ignasiseguravicente: The problem with it is that you're constantly altering your list lizt by doing the removes and trying to iterate over it.
Can't really say what's the bound between one and another.

Instead, try making a copy of it and iterating over that, it should work.

Q: But I'm doing that already.
A: Nope. You passed the reference of your list so anything you change inside your function, will change the original list. What you want to do is to copy the values stored on it.
Simply do:

newList = lizt[:]


Wow!! That was very helpful!! Thank you!:grinning:


def anti_vowel(text):
for i in text:
if i not in 'aeiouAEIOU':
return anti

print anti_vowel('Apple')