#coding = utf-8

def find_word(filename):
	resultdict={}
	with open(filename)as fp:
		for i in fp:
			print i
			wordlist=i.split()
			for j in wordlist:
				if not resultdict.has_key(j):
					resultdict[j]=1
				else:
					resultdict[j]+=1
	print resultdict
	sort_resultdict=sorted(resultdict.items(),key=lambda x:x[0],reverse=True)
	return sort_resultdict

print find_word("d:\\test.txt")[:6]

Logo

学大模型,用大模型上飞桨星河社区!每天8点V100G算力免费领!免费领取ERNIE 4.0 100w Token >>>

更多推荐