Skip to content

Commit

Permalink
counted zen.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
skysheng7 committed Jan 6, 2025
1 parent e5c2e4a commit 316f9a2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions src/pycounts_skysheng/pycounts_skysheng.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from collections import Counter
from string import punctuation


def load_text(input_file):
"""Load text from a text file and return as a string."""
with open(input_file, "r") as file:
text = file.read()
return text

def clean_text(text):
"""Lowercase and remove punctuation from a string."""
text = text.lower()
for p in punctuation:
text = text.replace(p, "")
return text

def count_words(input_file):
"""Count unique words in a string."""
text = load_text(input_file)
text = clean_text(text)
words = text.split()
return Counter(words)
21 changes: 21 additions & 0 deletions zen.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

0 comments on commit 316f9a2

Please sign in to comment.