the itertools and collections modules from collections import counter import re open'filename txtread(words re findall'\ ' lower() counter(wordsto print the ten most common wordswe can do the followingfor wordfreq in most_common( )print(word''freqto pick out only those words that occur more than five timeswe can do the following[word for word in if [word]> math with counters you can use some operators on counter objects here is some examplesc counter'aabbb ' counter'abccc ' + - & | counter({' ' ' ' ' ' }counter({' ' ' ' }counter({' ' ' ' }counter({' ' ' ' ' ' }doing + combines the counts from and dwhereas - subtracts the counts from from the corresponding counts of note that the counter returned by - does not include or negative counts the stands for intersection and returns the minimum of the two values for each itemand stands for union and returns the maximum of the two values defaultdict the collections module has another dictionary-like class called defaultdict it is almost exactly like an ordinary dictionary except that when you create new keya default value is given to the key here is an example that mimics what the counter class does 'aababcabcdabcd dd defaultdict(intfor in sdd[ ]+= defaultdict({' ' ' ' ' ' ' ' }