An open API service indexing awesome lists of open source software.

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.

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.