Advertisement
thaison1496

Untitled

Mar 29th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. import operator
  2. d={}
  3. for i in range(0,18):
  4. with open("Data\posts_"+str(i)+"_tok","r") as infile:
  5. #with open("posts_0_keys.txt","r") as infile:
  6. print i
  7. for line in infile:
  8. for word in line.split():
  9. if d.has_key(word):
  10. d[word]+=1
  11. else:
  12. d[word]=1
  13. sorted_d = sorted(d.items(), key=operator.itemgetter(1),reverse=True)
  14. with open("list_word.txt","w") as f:
  15. for i in sorted_d:
  16. f.write(i[0] + " " + str(i[1]) + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement