def answer_six(): from nltk.book import FreqDist dictionary = FreqDist(moby_tokens) sorted_dict = sorted(dictionary.items(), key=lambda x: x[1], reverse=True) result = [(v, k) for k, v in sorted_dict if ((v > 2000) & k.isalpha())] return result
def answer_eight(): from nltk.book import FreqDist part_of_speech = nltk.pos_tag(moby_tokens) tags = [t for _, t in part_of_speech] dictionary = FreqDist(tags) sorted_dict = sorted(dictionary.items(), key=lambda x: x[1], reverse=True) return sorted_dict[:5]
def answer_five(): from nltk.book import FreqDist dictionary = FreqDist(moby_tokens) sorted_dict = sorted(dictionary.items(), key=lambda x: len(x[0]), reverse=True) w, _ = sorted_dict[0] return (w, len(w))
def answer_three(): from nltk.book import FreqDist import operator token_dict = FreqDist(moby_tokens) sorted_token_dict = sorted(token_dict.items(), key=operator.itemgetter(1)) lst = sorted_token_dict[-20:] lst.reverse() return lst
def answer_three(): from nltk.book import FreqDist import operator token_dict = FreqDist(moby_tokens) sorted_token_dict = sorted(token_dict.items(), key=operator.itemgetter(1), reverse=True) return sorted_token_dict[0:20] # Your answer here
def answer_three(): from nltk.book import FreqDist dictionary = FreqDist(moby_tokens) sorted_dict = sorted(dictionary.items(), key=lambda x: x[1], reverse=True) return sorted_dict[:20]
def answer_four(): words_5 = [word for word in moby_tokens if len(word) > 5] print(words_5[:20]) dist = FreqDist(words_5) print(dist.items())