This commit is contained in:
2023-09-23 14:58:28 -04:00
parent 1e1e8f1f03
commit 385dafd1d1
3 changed files with 34 additions and 2 deletions

View File

@ -1,2 +1,15 @@
def word_stats(filename, n):
pass
words = open(filename).read().replace('\n', '').lower().split()
words = [''.join(e for e in w if e.isalpha()) for w in words]
out = {}
for word in words:
if word in out.keys():
out[word]['count'] += 1
else:
out[word] = {'count': 0, 'word': word}
out = sorted(out, key=lambda x:x[0])
return out
o = word_stats('article.txt', 5)