I forgot the command



Traceback (most recent call last):
File "python", line 6, in
File "python", line 4, in anti_vowel
TypeError: 'str' object does not support item deletion

def anti_vowel(text):
    for letter in text:
        if(letter in "aeiouAEIOU"):
            how do i remove a letter from a string?
        return text


i wouldn't even use delete, given you get a index shift. instead, before the loop make a empty list, append constants (if letter not in ...) to the list, then use .join() to join the list to a string

a function ends the moment a return keyword is reached, in your case in the first run of the loop, you might want to change the indent of return


i think i lost you with the join part


okay, for this exercise it is also possible to create an empty string, and append constants to it using += (update the variable, like so:

empty_list = empty_list + letter


Oops, try again. Does your anti_vowel function take exactly one argument (a string)? Your code threw a "can only concatenate list (not "str") to list" error.
it threw this error

def anti_vowel(text):
    for letter in text:
        if(letter not in "aeiouAEIOU"):
    return empty_list


if you use a list, you should use .append(), += is for strings (i would change empty_list into a empty_string). But if you have a list, you need to use .join() to convert the list (in the end) to a string


it says the join command can't be applied to a list


check documentation. And take a moment to think about how to solve this problem


wow thanks that really helped


To fill you in on a bit of theory/mentality you're missing:

You can't. They are immutable. You would instead create a new string without the letter that you want. If there are multiple such letters then that means that rather than create lots of new strings you would create one new string lacking all of those characters.

A list does not have this limitation, but you still would not want to do removals anywhere other than at or near the end because each removal involves moving all the following elements which can get costly for large numbers of operations on long lists. So again, creating a new one in one pass without the parts you want gone is the better approach.

You can implement anything you can describe in sufficient detail, just be aware that things have fixed behaviour regardless of what you want them to do. You may need some other thing or may want to use a different approach supported by the thing you're using.


yeah i already found that out, thanks to stetim94 but i appreciate your help.


I see that! Trying to give you the means to see why you'd do it one way over another, so that you're not left with just "here's how to do it" without being able to see why that's the way to go.


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