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


#1

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():
        text.remove(i)
  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?


#2

the problem is that here:

text.remove(i)

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


#3

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