词频统计
# with fo=open('Opium.txt','r') as f: fo = open(file='Opium.txt', mode='r') s=fo.read() fo.close() exclude_list=["'"] for exclude in exclude_list: s=s.replace(exclude," ") words=set(s.lower().split()) words=words-set({"a","the","am","to","i"}) dict={} for word in words: dict[word]=s.lower().count(word) dict=sorted(dict.items(),key=lambda x:x[1],reverse=True) print(dict[:10])