This commit is contained in:
wmantly committed 2023-09-23 14:58:28 -04:00
1 parent 1e1e8f1f03
commit 385dafd1d1
3 files changed
+34 -2

No files matched your search

+14 -1
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)