Expected:
>>> removeVowels('apple')
"ppl"
>>> removeVowels('Apple')
"ppl"
>>> removeVowels('Banana')
'Bnn'
Code (Beginner):
def removeVowels(word):
vowels = ('a', 'e', 'i', 'o', 'u')
for c in word:
if c in vowels:
res = word.replace(c,"")
return res
How do I both lowercase and uppercase?
Here is a version using a list instead of a generator:
You could also write it just as
Which does the same thing, except finding the non-vowels one at a time as
joinneeds them to make the new string, instead of adding them to a list then joining them at the end.If you wanted to speed it up, making the string of values a
setmakes looking up each character in them faster, and having the upper case letters too means you don’t have to convert each character to lowercase.