8, I need help


#1
def anti_vowel(hat):
    dog = ''
    vowel = ['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U']
    Hatlst = []
    for x in hat:
        if x != vowel:
            Hatlst.append(x)
    return hat
print anti_vowel('test')

#2

It just returns the original value, as if it has no effect


#3

You are returning hat and not Hatlst. Sometimes it helps to print certain things to find that out I just would print Hatlst after every Hatlst.append(x) that showed me that Hatlst had the right letters in it.


#4
def anti_vowel(hat):
    dog = ''
    vowel = ['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U']
    Hatlst = []
    for x in hat:
        if x != vowel:
            Hatlst.append(x)
            print Hatlst
    return str(Hatlst)
print anti_vowel('test')

Returns it as a list still. Also won't get rid of the vowels


#5
def anti_vowel(hat):
    dog = ''
    vowel = ['a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U']
    Hatlst = []
    for x in hat:
        if x != vowel:
            Hatlst.append(x)
            print Hatlst
    ''.join(Hatlst)
    print Hatlst
print anti_vowel('test')

when I print test, it is a list still, and doesn't exclude vowels. I am about to give up, been doing this for two hours


#6

If anyone could help me I would really apperciate it. I am struggling a good bit here.


#7

x != vowel will always be True, since no character equals a list of characters. Instead you want to use
if x not in vowel: to compare x against all the characters inside the list.


#8

How would I go about turning the list into a string?


#9

I think the most common way would be:

str = "".join(lst)

It basically means join together all elements of the list without anything in-between.

You could also simply write the characters into a string directly instead.