Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String replace vowels in Python?

Tags:

python

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?

like image 231
newbie Avatar asked Sep 04 '11 18:09

newbie


1 Answers

re.sub('[aeiou]', '', 'Banana', flags=re.I)
like image 160
JBernardo Avatar answered Oct 04 '22 00:10

JBernardo