Sie sind auf Seite 1von 1

import sys

from nltk import word_tokenize


from collections import Counter
from operator import itemgetter
import re

counter = Counter()
with open(sys.argv[1]) as f:
for line in f:
if re.match(r'^\s*$', line):
continue
line = line.strip().lower()
words = word_tokenize(line)
words = [word for word in words if word.isalpha()]
counter.update(words)
sorted_counter = sorted(counter.items(), key=itemgetter(1), reverse=True)
for word, num in sorted_counter:
print(word, num)

Das könnte Ihnen auch gefallen