8/15 how to replace something with nothing while keeping the string?


#1

‘def anti_vowel(text):
for x in text:
if x in “aeiouAEIOU”:
return x’

https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/antivowel?action=lesson_resume

error message unknown, trying to fix it finding how to skip/replace the letter with blank


#2

Hi @blogcoder18203,

In order to help you, we’re going to need a few things:

  • A link to the lesson
  • Your formatted code
  • Any and all error messages you have received

#3

Are you sure you want to return a single letter? Wouldn’t one need to complete iteration of the entire string before returning the revised version (sans vowels)?


#4

how? i understand that i am going through only one letter, but it s in a for loop, and i am very confused why it is happening.


#5

x is a single letter representation. Your code is saying to return it (the letter) if it is found in the vowel string. That means your function will terminate upon the first vowel found. We need to return only consonants, in a nearly complete word.


#6

‘def anti_vowel(text):
tex=list(text)
for x in text:
if x in ‘aeiouAEIOU’:
text.remove(x)
tex=str(tex)
return tex
’ maybe
should i just get the answer


#7

Strings are immutable so this will have no effect. However, you could try,

tex.remove(x)

since tex is a list, and .remove() is a list method. This way text is not changed and iteration can continue with no issues.


#8

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