Antivowel problem


def anti_vowel(x):
print x
for i in x:
for i in g:
if i in "aeiouAEIOU":
for i in g:
return f
print anti_vowel("Hey look Words!")

this is my code for the problem and it seems that the function anti_vowel returns "Hy lk Words!" instead of "Hy lk Wrds!" . Where am i wrong?


.remove() is really difficult approach, because you are dealing with index shifts.

the problem in this case is in look, when the first o is removed everything to the right of the removed character shifts to the left (because strings can't have empty indexes), while the loop progresses, causing successive vowels to skipped

its easier to use the opposite approach, append consonants to new list/string

if you really want to use remove, there are two ways to solve this, the easiest is to loop over x (the string) while removing from g (your list)


Thanks alot , took me while to understand , but i understood


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