count_words
- pyhelpers.text.count_words(raw_txt)[source]
Count the total for each different word.
- Parameters:
raw_txt (str) – any text
- Returns:
number of each word in
raw_docs
- Return type:
dict
Examples:
>>> from pyhelpers.text import count_words, remove_punctuation >>> raw_text = 'This is an apple. That is a pear. Hello world!' >>> count_words(raw_text) {'This': 1, 'is': 2, 'an': 1, 'apple': 1, '.': 2, 'That': 1, 'a': 1, 'pear': 1, 'Hello': 1, 'world': 1, '!': 1} >>> count_words(remove_punctuation(raw_text)) {'This': 1, 'is': 2, 'an': 1, 'apple': 1, 'That': 1, 'a': 1, 'pear': 1, 'Hello': 1, 'world': 1}