用户提问
#coding:utf-8
word_lst = []
word_dict = {}
with open(r"D:\Documents\SJTU\Work\frequency data\text\Sherlock Holmes.txt" , "r" , "gbk" ) as f1 , open(r"D:\Documents\SJTU\Work\frequency data\sinophenia-master\james\hanzi.output" , "w" ) as f2:
for line in f1:
word_lst.append(line)
for item in word_lst:
for item2 in item:
if ord(item2) > 0x4e00 and ord(item2) < 0x9fff :
if item2 not in word_dict:
word_dict[item2] = 1
else :
word_dict[item2] += 1
for key in word_dict:
print(key,word_dict[key])
f2.write(key+' '+str(word_dict[key]))
>>>
Traceback (most recent call last):
File "D:\Documents\SJTU\Work\frequency data\3rd.py", line 4, in
with open(r"D:\Documents\SJTU\Work\freque