You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
file = open('data.txt', mode='w')
for i in range(10963):
word, count = items[i]
print("{0:<10}{1:>5}".format(word,count))
new_context = word + " " + str(count) + '\n'
file.write(new_context)
file.close()
正则匹配结果
result = open('正则.txt', mode='w')
#存正则匹配的数组
things = []
#正则匹配:人物说的内容
for i in re.finditer("[说|道]:“(.+)\?”", txt):
message = i.group(1)
things.append(message)
#计数和展示
c = Counter(things)
for k, v in c.most_common(51):
print(k, v)
context = k + " " + str(v) + '\n'
result.write(context)
result.close()