Example usage

Here we will demonstrate how to use tutorialpackage to count words in a text file and then plot the first 5 most common words:

Imports

First of all, we need to import the package

from tutorialpackage.tutorialpackage import count_words
from tutorialpackage.tutorialpackage import count_words
from tutorialpackage.plotting import plot_words

Create a text file

First we create a text file to count the words

quote="""Insanity is doing things over and over again expecting different results
"""
with open("einstein.txt","w") as file:
    file.write(quote)

Count the words

Now we´ll count the words in the recently created quote

counts = count_words("einstein.txt")
print(counts)
Counter({'over': 2, 'insanity': 1, 'is': 1, 'doing': 1, 'things': 1, 'and': 1, 'again': 1, 'expecting': 1, 'different': 1, 'results': 1})

Plot words

We can now plot the results with the plot words function

fig = plot_words(counts,n=5)
_images/290ec7809306486d4043101a2ffec832ce24f7fb4c1561cc29cb7eb80ca117c1.png