Skip to content

Commit d10914f

Browse files
author
Chloe White
committed
added sample.txt file for my word frequency code as well as a README
1 parent 09163f1 commit d10914f

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

word_frequency/README.md

Whitespace-only changes.

word_frequency/counter_sample.txt

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from collections import Counter
2+
3+
def count_words(filename):
4+
with open(filename, "r", encoding="utf-8") as f:
5+
text = f.read().lower().split()
6+
word_counts = Counter(text)
7+
for word, count in word_counts.most_common(10):
8+
print(f"{word}: {count}")
9+
10+
if __name__ == "__main__":
11+
count_words("counter_sample.txt")

0 commit comments

Comments
 (0)