Skip to content

Instantly share code, notes, and snippets.

@prune998
Created February 1, 2017 19:50
Show Gist options
  • Save prune998/426772dd875a02f0741e19846efb5065 to your computer and use it in GitHub Desktop.
Save prune998/426772dd875a02f0741e19846efb5065 to your computer and use it in GitHub Desktop.
print word count and max appearence
#!/usr/bin/env python
import os
from pprint import pprint
word_list = {}
count = 0
with open("text.txt") as f:
for word in f.readline().split():
count += 1
if word in word_list.keys():
word_list[word] +=1
else :
word_list[word] = 1
print ("Total word count is %d" % count)
print ( sorted(word_list, key=word_list.__getitem__, reverse=True)[0:20])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment