去掉元音字母

'''
去掉给定字符串中的元音字母
'''

#解法1
def disemvowel(string):
    rlt=[]
    for i in string:
        if i.lower() not in 'aoeiu':
            rlt.append(i)
    return ''.join(rlt)

#解法2:
def disemvowel2(string):
    return ''.join(i for i in string if i.lower() not in 'aoeiu')

#解法3
def disemvowel3(s):
    for i in "aeiouAEIOU":
        s = s.replace(i,'')
    return s

#解法4
def disemvowel4(s):
    return filter(lambda x:x not in 'aoeiuAOEIU',s)

print(disemvowel3('calecongration'))
print(disemvowel4('calecongration'))

 

posted @ 2020-03-31 14:33  pple  阅读(306)  评论(0编辑  收藏  举报
以终为始,你期待的那天不会太遥远。