spark: add simple word counter tool

This commit is contained in:
spark committed 2026-10-27 16:56:47 +00:00
1 parent a9e92bde85
commit e0ff562bb2
4 files changed
+37

No files matched your search

View File
Whitespace-only changes.
+1
View File
@@ -0,0 +1 @@
Hello world this is test seven words
+21
View File
@@ -0,0 +1,21 @@
# Word Counter
A simple Python word counter that counts words in a text file.
## Usage
```bash
python3 word-counter.py <filepath>
```
## 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
+15
View File
@@ -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 <filepath>")
sys.exit(1)
print(count_words(sys.argv[1]))