https://github.com/qtle3/word_frequency
This Python script calculates and displays the frequency of words in a specified text file. It reads the contents of the file, counts the occurrences of each word, and then outputs the words sorted by their frequency.
https://github.com/qtle3/word_frequency
Last synced: about 1 year ago
JSON representation
This Python script calculates and displays the frequency of words in a specified text file. It reads the contents of the file, counts the occurrences of each word, and then outputs the words sorted by their frequency.
- Host: GitHub
- URL: https://github.com/qtle3/word_frequency
- Owner: qtle3
- Created: 2024-08-08T04:50:34.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-10T04:25:13.000Z (almost 2 years ago)
- Last Synced: 2025-02-14T16:01:53.090Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Word Frequency Counter
This Python script calculates and displays the frequency of words in a specified text file. It reads the contents of the file, counts the occurrences of each word, and then outputs the words sorted by their frequency.
## Key Concepts Covered
- **File Handling**: The script demonstrates how to open, read, and process the contents of a text file using Python's built-in `open()` function.
- **Word Counting**: The script counts the occurrences of each word in the text file and stores them in a dictionary, where the keys are the words and the values are their respective frequencies.
- **Sorting**: The script sorts the words by their frequency using a custom sorting function (`byFreq`), making it easy to identify the most and least common words.
- **Input Handling**: The script prompts the user to enter the name of the text file to be analyzed, ensuring flexibility in processing different files.