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

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197

1 Answers1

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}
Chris_Rands
  • 38,994
  • 14
  • 83
  • 119
  • 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 – Gurps Singh Feb 28 '18 at 15:03