Python实现字频统计

       
-------------已经到底啦!-------------
 

做题时遇到大量字符串怎么办??

利用collection模块简化代码

1
2
3
4
5
6
7
8
from collections import Counter

with open("flag.txt") as f:
text_list = f.readlines()
'''将读取的内容转换为字符串'''
text_str = ''.join(text_list)
count = Counter(text_str)
print (count)