统计字符串中的元音

2016-07-11  本文已影响13人  zhangxu0636
#统计字符串中的元音总个数
def calculate(source):
    a = ["a","e","i","o","u"]
    return sum([1 for e in source if str.lower(e) in a])
#统计各个元音的个数
def caculate1(source):
    m = {}
    a = ["a","e","i","o","u"]
    for e in source:
        if str.lower(e) in a:
            if str.lower(e) in m:
                m[str.lower(e)] = m[str.lower(e)] + 1
            else:
                m[str.lower(e)] = 1
    return m
上一篇 下一篇

猜你喜欢

热点阅读