4.1 Applied Python (Advanced Course) https://brilliant.org/courses/python-text-analysis/dictionaries-and-counters/?from_llp=computer-science
4.1 Applied Python (Advnaced Course)
https://brilliant.org/courses/python-text-analysis/dictionaries-and-counters/?from_llp=computer-science
Lesson 3 Counting Unique Words
Instead of dictionary use Counter() function it is more handly
No need to initialized any key before adding any addition:
Modify this program to use a Counter rather than a dictionary, and print the if statement
I have change to Counter() in place of using dictionary.
Dictionaries and counters are mutable (chnagable), but their keys can't be.
We can iterate through a tuple, or retrieve an element, but methods like append and pop that change lists don't exist for tuples, because tuples are immutable.
Bigram Frequency
This program applies the same logic to the whole text. We'll use it to find out more about the frequency of different bigrams.
We can check how often each character appears in the text by looking up their names as bigrams.
Note: must lower case and without any puctuation like .
To use the bigram as a key, we converted it to a tuple.
To count the number of times each bigram appears, we used a
Counterobject.
N-gram Analysis
The three bigrams are ("the", "honour"), ("honour", "the") and ("the", "sanity").
Comments
Post a Comment