Skip to content

Commit 8d8d056

Browse files
committed
Added requirments.txt file
1 parent e4199e3 commit 8d8d056

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

Word_frequency_counter/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Word Frequency Counter
2+
3+
A simple python script that counts the number of words in a given text document and prints the top 10 words according to their frequency, along with their frequency of occurence.
4+
5+
---
6+
7+
- **Input :** Path of the text file to be processed
8+
- **Output :** List of top 10 words according to their frequency, along with their frequency of occurence.
9+
10+
---
11+
12+
## Features :
13+
14+
- User friendly interface
15+
- Output is in tabular format
16+
- Case insensitive processing of words
17+
- Get the Top 10 words in the text file which occur most frequntly, along with their counts
18+
19+
---
20+
21+
## Usage :
22+
23+
1. Clone the repository
24+
2. Navigate to the project folder
25+
3. Run the command :
26+
27+
```python
28+
python3 main.py
29+
```

Word_frequency_counter/main.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import regex as re
2+
from collections import Counter
3+
4+
def find_words_frequency(file_path):
5+
'''
6+
This script takes the path of the text file to be processed as input
7+
and prints the top ten words and also prints their counts in the given text file.
8+
'''
9+
with open(file_path, 'r', encoding='utf-8') as file:
10+
text = file.read().lower()
11+
12+
# Use `regex`'s findall function
13+
all_words = re.findall(r'\b\p{L}+\b', text)
14+
word_frequency = Counter(all_words)
15+
most_common_words = word_frequency.most_common(10)
16+
17+
# Print in tabular format
18+
print(f"{'Word':<15} {'Count':<5}")
19+
print("-" * 20)
20+
for word, count in most_common_words:
21+
print(f"{word:<15} {count:<5}")
22+
23+
def main():
24+
file_path = input("Enter the path of file : ")
25+
find_words_frequency(file_path)
26+
27+
if __name__ == "__main__":
28+
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
regex=2.5.147

Word_frequency_counter/runtime.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-3.10.7

0 commit comments

Comments
 (0)