spark: add simple word counter tool
This commit is contained in:
1 parent
a9e92bde85
commit
e0ff562bb2
4 files changed
+37
No files matched your search
Whitespace-only changes.
@@ -0,0 +1 @@
|
||||
Hello world this is test seven words
|
||||
@@ -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
|
||||
Executable
+15
@@ -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]))
|
||||
Reference in new issue
Block a user