8.index problem=(


#1



8.anti_vowel


Your function fails on anti_vowel("Hey look Words!"). It returns "Hy lk Words!" when it should return "Hy lk Wrds!".:sweat:
Something went wrong, even in the compiler on my computer it shows with "o" in the "words" and at this point I have no idea what is wrong...


It is supposed to remove all the vowels in the string.

def anti_vowel(text):
    text=list(text)
    vowels="oaeiouAEIOU"
    s=str()
    for letter in text:
        if letter in vowels:
            del text[text.index(letter)]
    s="".join(text)
    return s


#2

Hi
it is not a good idea to modify the object on which you are looping. It is not surprising if you have then problems with indexes. You can track your problem by printing out intermediate results in the loop. For this kind of function, I would rather create a second string which is empty at the beginning, iterate on the initial string but modify the second string by adding character by character if it is not a vowel.

Cheers


#3

try this it's more easy

def anti_vowel (text):
    result = ""
    for l in text :
        if l not in "aeiouAEIOU" :
            result += l
    return result

#4

@yanmakouski You seem to be confusing yourself with excessive steps in the code that really aren't needed. For example, I'm not surewhy you worte this but it isn't necessary:

Also, you do not need to remove the vowels, and then add them into a new string, simply replace the vowels with nothing. If you do all I have said, your code should resemble this:

def anti_vowel(text):
    text = str(text)
    vowels = "aeiouAEIOU"
    for letter in text:
        if letter in vowels:
           text = text.replace(letter,"")
    return text

Hope that helps! :slight_smile:

-- @chipjumper36731


#5

Thanks a lot. This is much easier than changing the string to a list, and then removing the vowels from the list and then change the list to a string and finally return the string.
Though I can still can't understand why didn't the function remove the "o" letter in (Words). Can you explain this issue for me?
Thank you in advance.


#6

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