字符串练习

 

def func(s):
    dic = {'num': 0, 'alpha': 0, 'space': 0, 'other': 0}
    for char in s:
        if char.isdigit():
            dic['num'] += 1
        elif char.isalpha():
            dic['alpha'] += 1
        elif char.isspace():
            dic['space'] += 1
        else:
            dic['other'] += 1
    return dic


print(func("s100www:// 3vv- w2jfk"))

 

posted @ 2020-05-05 00:00  CherryYang  阅读(82)  评论(0)    收藏  举报