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

However it produces "Hy" when run.

vowels = {
    'a': ['a','A'],
    'e': ['e','E'],
    'i': ['i','I'],
    'o': ['o','O'],
    'u': ['u','U']        

def anti_vowel(text):
    new_string = ('')
    for c in text:
        if c in vowels:
            new_string = text.replace(c,'')
    return new_string



This doesn't change the value of text. In the loop you make new_string the same as text with one vowel removed. The next time the loop runs the old vowel will be there again and the next one will be removed.

Also I don't think a dictionary is the right thing to use here. You only go through the keys, that means capital vowels won't be deleted.


def anti_vowel(text):
    vowels = ('aeiouAEIOU')
    for c in text:
        if c in vowels:
            text = text.replace(c,'')
    return text

Lesson cleared. Thanks.


No problem.

You should also be careful with looping through the text variable while changing it, although that shouldn't be a problem in this case.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.