example_package.counts

Functions

load_text(file_path)

Load text from a file.

clean_text(text)

Clean the text by removing punctuation and converting to lowercase.

count_words(input_file)

Count the frequency of each word in the input file.

Module Contents

example_package.counts.load_text(file_path)[source]

Load text from a file.

example_package.counts.clean_text(text)[source]

Clean the text by removing punctuation and converting to lowercase.

example_package.counts.count_words(input_file)[source]

Count the frequency of each word in the input file.

Parameters:

input_file (str) – Path to the text file to analyze.

Returns:

A Counter object containing word frequencies where:
  • keys are the unique words found in the text

  • values are the number of occurrences of each word

Return type:

Counter

Example

>>> word_counts = count_words("sample.txt")
>>> word_counts["hello"]
3
>>> word_counts.most_common(1)
[('hello', 3)]