Dictionary

1.DICTIONARY OPERATIONS

2.Example with a Dictionary

def words_often(freqs, minTimes):
    result = []
    done = False
    while not done:
        temp = most_common_words(freqs)
        if temp[1] >= minTimes: 
            result.append(temp)
            for w in temp[0]:
                del(freqs[w])  #remove word from dictionary
        else:
            done = True
    return result

temp = most_common_words(freqs)选出目前freqs中最多的词以及出现次数,返回(words,best)。

result.append 则把这次的(words,best)写入 result。

del(freqs[w])从freqs这个词典中去掉这个(words,best)

在while里面继续循环,直到没有temp[1]>= minTimes。

所以freqs是被删掉了(words,best)的。

3.利用dictionary提升计算效率

Memoization

results matching ""

    No results matching ""