8. anti_vowel!


#1

Hi everyone,
I tried both .remove method and del function but i cant remove all 3 o's in sentence.

def anti_vowel(text):
lst = []
for i in text:
    lst.append(i)
for i in lst:
    if i in "aeiouAEIOU":
        index = lst.index(i)
        del lst[index]
str_lst = "".join(lst)
return str_lst

Oops, try again. Your function fails on anti_vowel("Hey look Words!"). It returns "Hy lk Words!" when it should return "Hy lk Wrds!".

Why it fails?


#2

i go with this way

def anti_vowel(text):
lst = []
for i in text:
    lst.append(i)
no_vowel = []
for i in lst:
    if i not in "aeiouAEIOU":
        no_vowel.append(i)
str_no_vowel = "".join(no_vowel)
return str_no_vowel

#3

I couldn't figure out how to remove items either, so I went the other way and made a new list not including vowels. Here are two similar methods:

menu = "cheesepizza"

def anti_vowel(text):
    new_text = ""
    vowels = "aeiouAEIOU"
    for char in text:
        if char not in vowels:
            new_text += char
    return new_text
print anti_vowel(menu)

# chspzz

def anti_vowel2(text):
    new_text = []
    vowels = "aeiouAEIOU"
    for char in text:
        if char not in vowels:
            new_text.append(char)
    return "".join(new_text)
    
print anti_vowel2(menu)

# chspzz

#4

This is the simplest way.

def anti_vowel(text):
word = []
for each in text:
    if each not in "aeiouAEIOU":
        word.append(each)
return "".join(word)

No need to go through assign everything to a list and then check and remove - just don't add them in the first place :smile: