pycounts.pycounts
¶
Module Contents¶
Functions¶
|
Load text from a text file and return as a string. |
|
Lowercase and remove punctuation from a string. |
|
Count words in a text file. |
- pycounts.pycounts.load_text(input_file)[source]¶
Load text from a text file and return as a string.
- Parameters
input_file (str) – Path to text file.
- Returns
Text file contents.
- Return type
str
Examples
>>> load_text("text.txt")
- pycounts.pycounts.clean_text(text)[source]¶
Lowercase and remove punctuation from a string.
- Parameters
text (str) – Text to clean.
- Returns
Cleaned text.
- Return type
str
Examples
>>> clean_text("Early optimization is the root of all evil!") 'early optimization is the root of all evil'
- pycounts.pycounts.count_words(input_file)[source]¶
Count words in a text file.
Words are made lowercase and punctuation is removed before counting.
- Parameters
input_file (str) – Path to text file.
- Returns
dict-like object where keys are words and values are their counts.
- Return type
collections.Counter
Examples
>>> count_words("text.txt")