小编Fra*_*ith的帖子

如何计算Str中的重复字符数

每个人我只是想知道如何计算str中ch的重复,我写的函数是:

def repeat(s):
    '''
    '''
    count = 0 
    L = []

    for i in range(len(s)):
        count = 0
        if s[i] in s: 
         count = count + 1
        else:
             count = count

    L.append(count)
    return L
Run Code Online (Sandbox Code Playgroud)

但是,如果字母相同,列表将重复.是否有更好的方法来计算str中的字符数量?我在考虑使用字典?

python string python-3.x

1
推荐指数
1
解决办法
243
查看次数

标签 统计

python ×1

python-3.x ×1

string ×1