相关疑难解决方法(0)

用Python相交两个词典

我正在研究一个倒排索引的搜索程序.索引本身是一个字典,其键是术语,其值本身是短文档的字典,ID号作为键,其文本内容作为值.

为了对两个术语执行"AND"搜索,我需要与他们的帖子列表(词典)相交.在Python中做这个的明确(不一定是过于聪明)的方法是什么?我开始尝试很长的路iter:

p1 = index[term1]  
p2 = index[term2]
i1 = iter(p1)
i2 = iter(p2)
while ...  # not sure of the 'iter != end 'syntax in this case
...
Run Code Online (Sandbox Code Playgroud)

python iteration dictionary intersection

62
推荐指数
4
解决办法
6万
查看次数

标签 统计

dictionary ×1

intersection ×1

iteration ×1

python ×1