Python, Unit 8: Practice Makes Perfect - "anti-vowel"


I don’t understand why this doesn’t work, the code returned me an error saying
"AttributeError: ‘str’ object has no attribute ‘remove’"

Here’s my code:

def anti_vowel(text):
  vowels = ["A", "E", "I", "O", "U"]
  for k,i in enumerate(text):
    for p in range(5):
      if text[k] == vowels[p] or \
      text[k] == vowels[p].lower():
  return text
print (anti_vowel("Hey You!"))

It states the error occurred at line 7, being “text.remove(i)” - I’ve debugged and checked that i is a string (just has to be), so why did I get an error?


the problem is that here:


text is a string, string does not have remove method. .remove() is a method belonging to list


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