I'm pretty sure my code is correct but it doesn't seem to returning the expected output:
input anti_vowel("Hey look words")
--> outputs: "Hey lk wrds"
.
Apparently it's not working on the 'e'
, can anyone explain why?
def anti_vowel(c):
newstr = ""
vowels = ('a', 'e', 'i', 'o', 'u')
for x in c.lower():
if x in vowels:
newstr = c.replace(x, "")
return newstr
i hope this helps..
The function
str.replace(old, new[, max])
don't changesc
string itself (wrt toc
you calls) just returns a new string which the occurrences of old have been replaced with new. Sonewstr
just contains a string replaced by last vowel inc
string that is theo
and hence you are getting"Hey lk wrds"
that is same as"Hey look words".replace('o', '')
.I think you can simply write
anti_vowel(c)
as:What I am doing is iterating over string and if a letter is not a vowel then only include it into list(filters). After filtering I join back list as a string.
A fairly simple approach could be;
Try String.translate.
https://docs.python.org/2/library/string.html#string.Template.substitute
Or if you're using the newfangled Python 3: