在Python中查找嵌套列表的交集?

在Python中查找嵌套列表的交集?,python,list,intersection,Python,List,Intersection,这是查询的结果[0,2,3,4,6][1,4,5][0,2,4][4,5] 查询采用用户输入的术语(“qtext”),标记化并为每个标记生成一个帖子列表 发布列表是嵌套字典的列表(例如,[0:0.68426,1:0.26423},{2:0.6842332,0:0.9823})。我正在尝试使用键查找这些嵌套字典的交集假设顺序无关紧要,您可以使用set.intersection(): 假设顺序无关紧要,可以使用set.intersection(): def query_RR(posting,qtex

这是查询的结果[0,2,3,4,6][1,4,5][0,2,4][4,5]

查询采用用户输入的术语(“qtext”),标记化并为每个标记生成一个帖子列表


发布列表是嵌套字典的列表(例如,[0:0.68426,1:0.26423},{2:0.6842332,0:0.9823})。我正在尝试使用键查找这些嵌套字典的交集

假设顺序无关紧要,您可以使用
set.intersection()


假设顺序无关紧要,可以使用
set.intersection()

def query_RR(posting,qtext):words=tokenize(qtext)allposting=[posting[w]for w in words]for a in all posting:print a.keys(),这是查询[0,2,3,4,6][1,4,5][0,2,4][4,5]的结果。查询采用用户输入的术语(“qtext”),标记化并为每个标记生成一个发布列表。发布列表是一个嵌套字典的列表(例如,[{0:0.68426,1:0.26423},{2:0.6842332,0:0.9823}]。我正在尝试使用keysdef查询_RR(发布,qtext):words=tokenize(qtext)allposting=[postings[w]for w in words]for a in allpostings:print a.keys()这是查询[0,2,3,4,6][1,4,5][0,2,4][4,5]的结果。查询采用用户输入的术语('qtext'),标记化并为每个标记生成一个发布列表。发布列表是一个嵌套字典列表(例如[{0:0.68426,1:0.26423},{2:0.6842332,0:0.9823}]。我正在尝试使用键查找这些嵌套字典的交集
def query_RR(postings, qtext): 
words = tokenize(qtext) 
allpostings = [postings[w] for w in words]
for a in allpostings: 
print a.keys()
>>> 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}