Created
February 1, 2017 19:50
-
-
Save prune998/426772dd875a02f0741e19846efb5065 to your computer and use it in GitHub Desktop.
print word count and max appearence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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