1
def query_RR(postings, qtext): 
words = tokenize(qtext) 
allpostings = [postings[w] for w in words]
for a in allpostings: 
print a.keys()

And this was the result of the query [0, 2, 3, 4, 6] [1, 4, 5] [0, 2, 4] [4, 5]

The query is taking a user inputted term ('qtext'), tokenizing and generating a postings list for each token.

The posting list is a list of nested dictionaries (e.g. [{0 : 0.68426, 1: 0.26423}, {2: 0.6842332, 0: 0.9823}]. I am attempting to find the intersection for these nested dictionaries using the keys

0

1 Answer 1

5

Assuming the order does not matter, you could use set.intersection():

>>> lst = [[0, 2, 3, 4, 6], [1, 4, 5], [0, 2, 4], [4, 5]]
>>> set.intersection(*map(set,lst))
{4}
>>> set(lst[0]).intersection(*lst[1:])
{4}
Sign up to request clarification or add additional context in comments.

1 Comment

def query_RR(postings, qtext): words = tokenize(qtext) allpostings = [postings[w] for w in words] for a in allpostings: print a.keys() And this was the result of the query [0, 2, 3, 4, 6] [1, 4, 5] [0, 2, 4] [4, 5] The query is taking a user inputted term ('qtext'), tokenizing and generating a postings list for each token. The posting list is a list of nested dictionaries (e.g. [{0 : 0.68426, 1: 0.26423}, {2: 0.6842332, 0: 0.9823}]. I am attempting to find the intersection for these nested dictionaries using the keys

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.