From e0ff562bb2ba741652c6449e224618aca0001d4d Mon Sep 17 00:00:00 2001 From: spark Date: Tue, 27 Oct 2026 16:56:47 +0000 Subject: [PATCH] spark: add simple word counter tool --- wizard-work/spark/test-empty.txt | 0 wizard-work/spark/test-input.txt | 1 + wizard-work/spark/word-counter-README.md | 21 +++++++++++++++++++++ wizard-work/spark/word-counter.py | 15 +++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 wizard-work/spark/test-empty.txt create mode 100644 wizard-work/spark/test-input.txt create mode 100644 wizard-work/spark/word-counter-README.md create mode 100755 wizard-work/spark/word-counter.py diff --git a/wizard-work/spark/test-empty.txt b/wizard-work/spark/test-empty.txt new file mode 100644 index 0000000..e69de29 diff --git a/wizard-work/spark/test-input.txt b/wizard-work/spark/test-input.txt new file mode 100644 index 0000000..99f2a300 --- /dev/null +++ b/wizard-work/spark/test-input.txt @@ -0,0 +1 @@ +Hello world this is test seven words \ No newline at end of file diff --git a/wizard-work/spark/word-counter-README.md b/wizard-work/spark/word-counter-README.md new file mode 100644 index 0000000..52ac360 --- /dev/null +++ b/wizard-work/spark/word-counter-README.md @@ -0,0 +1,21 @@ +# Word Counter + +A simple Python word counter that counts words in a text file. + +## Usage + +```bash +python3 word-counter.py +``` + +## Example + +```bash +$ python3 word-counter.py test-input.txt +7 +``` + +## Verification + +- 7 words in test-input.txt: PASS +- 0 words in test-empty.txt: PASS \ No newline at end of file diff --git a/wizard-work/spark/word-counter.py b/wizard-work/spark/word-counter.py new file mode 100755 index 0000000..5cabee9 --- /dev/null +++ b/wizard-work/spark/word-counter.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +"""Simple word counter - counts words in a text file.""" +import sys + +def count_words(filepath): + """Count words in a file and return the total.""" + with open(filepath, 'r') as f: + text = f.read() + return len(text.split()) + +if __name__ == '__main__': + if len(sys.argv) != 2: + print("Usage: word-counter.py ") + sys.exit(1) + print(count_words(sys.argv[1])) \ No newline at end of file