Intersecting two dictionaries in Python
I am working on a search program over an inverted index. The index itself
is a dictionary whose keys are terms and whose values are themselves
dictionaries of short documents, with ID numbers as keys and their text
content as values.
To perform an 'AND' search for two terms, I thus need to intersect their
postings lists (dictionaries). What is a clear (not necessarily overly
clever) way to do this in Python? I started out by trying it the long way
with iter:
p1 = index[term1]
p2 = index[term2]
i1 = iter(p1)
i2 = iter(p2)
while ... # not sure of the 'iter != end 'syntax in this case
...
No comments:
Post a Comment