Anti vowel


#1

Ok, how do you propose we append consonants to a new list, because I've had this issue (even though it now seems to be working for everything BUT codecademy's input), and I changed it up to append instead of remove, but it is now adding everything, not just the consonants!

def anti_vowel(text):
    letters = list(text)
    print letters
    vowel = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
    for v in vowel:
        novowel= []
        for l in letters:
            if v != l :
                novowel.append(l)
    print novowel
    text = "".join(novowel)
    return text

I just don't know how to fix this, I feel like I've tried everything.


Anti-Vowel - Loop don't detect all vowels
#2

simple use one loop to loop over letters, then use a if condition (if letter not in vowel), then append the constant to novowel

Also make sure you declare novowel outside the for loop, otherwise it gets resetted every time


#3

Isn't that what I did?


#4

no, your first loop over your vowels, each time you do this, you make no_vowel empty again, then for one vowel, you are going over the letters, append constants to the list, but because the list resets every time, so at the last vowel of your vowel list, all letters except U get appended to your novowel list, which gets returned

Using two loops is a bad idea. And defining a list in which you want to store the result inside a loop is also a bad idea

maybe add a function call and some print statements so you can actually see what your program is doing?


#5

I've been adding prints, etc. so I can see the output. You're right about the for loops, that was left over from when I was removing, so I got rid of it. I'm still not getting something, though. This is what I have now, and it's doing the same thing it was before:

def anti_vowel(text):
    letters = list(text)
    print letters
    vowel = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]
    novowel= []
    for l in letters:
        if l != vowel :
            novowel.append(l)
    print novowel
    text = "".join(novowel)
    return text

#6

Ok, I didn't realize you could specify "not in" is that something from the previous lessons or did I forget it? The section on lists is really letting me down right now. But I got it, so thanks.


#7

def anti_vowel(text):
k = []
s = ""
for i in range(0,len(text),1):
if text[i] == "a" or text[i] == "A" or text[i] == "e" or text[i] == "E" or text[i] == "i" or text[i] == "I" or text[i] == "o" or text[i] == "O" or text[i] == "u" or text[i] == "U":
k.append("")
else:

        k.append(text[i])
s = "".join(k)
return s

just remove the "text" var at the second last line and def new empty string and save it to that
see in my code


#8

did you solve it? Well the in word is covered, pretty sure, and the not as well, so then you would have to combine it yourself


#9

Yes, I did! I just didn't understand how "in" was being used by Python. It was implied, but I don't remember it being stated outright, although I was using it for my "for" loops. But I think I understand it now. It basically refers to everything that's in the list (so the program has to check the whole list).

Thanks again for your help, Stetim94.