布隆算法算法
先來看幾個比較常見的例子數組
這幾個例子有一個共同的特色: 如何判斷一個元素是否存在一個集合中?網絡
對於低內存的字典,方法以下:spa
1
import jieba 2 def check(s): 3 huangfan_path = 'path/to/dict.txt' 4 jieba.load_userdict(huangfan_path) 5 huangfan_words_dict = set() 6 with open(huangfan_path, 'rb') as fr: 7 for line in fr.readlines(): 8 huangfan_words_dict.add(line.strip().decode('utf-8')) 9 return set(jieba.lcut(s)) & self.huangfan_words_dict