from collections import Counter↵
import re↵
import sys↵
↵
↵
def top_words(path, n=10):↵
with open(path, encoding="utf-8") as f:↵
words = re.findall(r"[a-z']+", f.read().lower())↵
return Counter(words).most_common(n)↵
↵
↵
if __name__ == "__main__":↵
for word, count in top_words(sys.argv[1]):↵
print(f"{count:6} {word}")
Click here or press any key to type