python 统计2^2^2^2^2的各数字出现次数

包含的知识点:

1. 拆分字符串

2. 默认字典

>>> import collections
>>> d=collections.defaultdict(int) #注意填参数int
>>> bignum=list(str(2**2**2**2**2)) #list可以拆分字符串为单字符
>>> len(bignum)
19729
>>> for num in bignum:
    d[num]+=1

    
>>> for n in d:
    print(d[n])

    
1972
1948
1978
1984
1903
1977
1983
1984
1943
2057

 

posted on 2018-09-02 00:27  Ricochet!  阅读(504)  评论(0编辑  收藏  举报