zxt-cn
方法一
from collections import Counter

import re

with open(\'../one_one.py\',encoding="utf-8",)as f:
f1 = f.read()
rest = re.findall(r\'[a-zA-Z].+\',f1)

res = Counter(rest)
print(res)
for k,l in res.items():
print("%s:%s" % (k,l))

方法二
import re
with open(\'../one_one.py\',encoding="utf-8", )as f:
f1 = f.read()
f2 = re.sub(r"[.?!,()/#:\'=->]", \' \', f1)
res = f1.split()
print(res)
dict1 = {}
for k in res:
if re.findall(r\'[a-zA-Z]\',k):
ress = res.count(k)
dict1[k] = ress
print(dict1)
ll = sorted(dict1.items(),key=lambda x:x[1],reverse=True)
print(ll)

分类:

技术点:

相关文章: