Skip to content

Instantly share code, notes, and snippets.

@gibizer
Created December 19, 2019 11:51
Show Gist options
  • Save gibizer/8a6fa01a14fcd177008dbb5406f40b36 to your computer and use it in GitHub Desktop.
Save gibizer/8a6fa01a14fcd177008dbb5406f40b36 to your computer and use it in GitHub Desktop.
import collections
counter = collections.Counter()
word = ""
with open('sherlock.txt') as f:
while True:
c = f.read(1)
if not c:
break
if c.isalnum():
word += c.lower()
else:
if word != "":
counter[word] +=1
word = ""
for w, c in counter.most_common(20):
print(w, c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment