Why dosn't this code work?


def anti_vowel(text):
    for i in range(0,len(T)):
        for l in L:
            if l==x:
    return "".join(L)

Continuing the discussion from 8. Anti-Vowel:


Because remove a particular bad idea for this problem, why? the moment you remove a item, the index is going to shift, really simple example:

t   e   a   r
0   1   2   3

i put spaces in so you can see it better. Now, the moment the e at index one gets removed, everything shifts, so the a will end up at index one, but the loop will just going to the next position (the counter of the loop increases), so the a gets skipped.

Now, it can be done with remove, but you need a while loop, which is causing index problems, so you need to catch that. Bad idea, i recommend to append consonants to a new list, and then join that


There are few mistakes in your code first you haven't lopped through your text and by stating range you are compairing numbers.
To make it work first
Make a empty string like words = ""
then you have to loop through text like this
for i in text:
then compair that i to the string T
if i not in T:
append the i to the words
then joint them with empty space
return words


Got it, thank you a lot


@s09abcd, i agree there are mistakes. But i disagree with this:

He is looping through the vowels here:

for i in range(0,len(T)):

then converting the number into letter (vowel):


then he loops through the text:

for l in L:

i will give you this is not the most efficient, looping for each vowel over the entire text. But it is happening


opps my bad that was kind of long way to loop through but make scence.


I agree with you on that, absolutely :slightly_smiling: Actually, his method could have worked, but then you have to keep looping over the vowels until no more vowels are there, but that is such a resource waste. But good to hear we agree :slightly_smiling:


Sorry, but my looping inside L=list(text) was through items itself instead of indexs, so removing dose not affect the process of looping . I just want to mention that I tried this solution in the "Interactive Editor for Python" and it dose work !
So I'm a little bit confused


I'm sure we both did something like that when we first started programming :slightly_smiling: at least i did :smile:


@boudalh, did you run all the cases the exercise did? The exercise runs many different sentences to validate your code is absolutely correct

@s09abcd, yes, agree. I hope you saw my remark as positive feedback to help you :slightly_smiling: You can learn from helping other people


Yes, of course it is helpful thanks