示例#1
0
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
示例#2
0
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]
示例#3
0
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))
示例#4
0
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
示例#5
0
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
示例#6
0
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]
示例#7
0
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())