Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import operator
- d={}
- for i in range(0,18):
- with open("Data\posts_"+str(i)+"_tok","r") as infile:
- #with open("posts_0_keys.txt","r") as infile:
- print i
- for line in infile:
- for word in line.split():
- if d.has_key(word):
- d[word]+=1
- else:
- d[word]=1
- sorted_d = sorted(d.items(), key=operator.itemgetter(1),reverse=True)
- with open("list_word.txt","w") as f:
- for i in sorted_d:
- f.write(i[0] + " " + str(i[1]) + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement