8/15 anti_vowel: Practice Makes Perfect


#1

This is my code right now:

def anti_vowel(text):
lizt = list(text)
for letter in lizt:
if letter in 'aeiouAEIOU':
lizt.remove(letter)
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?


#2

@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[:]

#3

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


#4

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

print anti_vowel('Apple')