February 2018
Beginner to intermediate
364 pages
10h 32m
English
We can also use this to identify the least common words, by slicing the result of .most_common() with a negative value. As an example, the following finds the 10 least common words:
print(freq_dist.most_common()[-10:])[('bitten', 1), ('gibber', 1), ('fiercer', 1), ('paler', 1), ('uglier', 1), ('distortions', 1), ('haunting', 1), ('mockery', 1), ('beds', 1), ('seers', 1)]
There are quite a few words with only one occurrence, so this only gets a subset of those values. The number of words with only one occurrence can be determined by the following (truncated due to there being 3,224 words):
dist_1 = [item[0] for item in freq_dist.items() if item[1] == 1]print(len(dist_1), dist_1)3224 ['dwell', 'inhabited', 'lords', 'kepler', ...
Read now
Unlock full access