8, 2.2, "anti_vowel". This Code Works On Repl But Does Not Work At All Here. Why?


#1
def anti_vowel(text):
	x = "a e i o u"
	for i in text:
		if i.lower in text.split():
			y = text.find(i)
			text = text[:y] + text[y + 1:]
	return text

#2

Hi @billy_the_kid88,

What result do you see that indicates that your code does not work in the Codecademy environment?

What result do you see that indicates that your code works on Repl?


#3

“text.split()” at line 4 was meant to be “x.split()”. That is what works in repl and what i am using. To be clear, the correction here in this post is the code that i am using that does not work.


#4

“Your function fails on anti_vowel(“Hey look Words!”). It returns “Hey look Words!” when it should return “Hy lk Wrds!”.”

on Repl it says “Hy lk Wrds!”

The code that i used in the above post was transcribed incorrectly. “text.split()” is actually “x.split()”. This does not work.


#6

Here, you establish a loop that iterates through text

  for i in text:

However, this line assigns an altered value to text

    text = text[:y] + text[y + 1:]

Altering the sequence as you iterate through it interferes with the iteration process.

Instead, assign a new empty list to a new variable prior to the loop. Then, inside the loop, append characters from text that are not vowels to that new list. Finally, after the loop, return that new list.


#7

@applylpye

I I forgot the parentheses in i.lower(). it works now. my bad.


#8

Glad it works.

Regarding my statement …

Altering the sequence as you iterate through it interferes with the iteration process.

… technically, you were not altering the original sequence pointed to by text. Rather, you assigned a new value to text.


#9

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