Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在两个水平列表之间相交一系列列?_Python_List_Intersection - Fatal编程技术网

Python 如何在两个水平列表之间相交一系列列?

Python 如何在两个水平列表之间相交一系列列?,python,list,intersection,Python,List,Intersection,在我编写的代码中,我需要将两个水平列表相交,如: listA: 列表B 如何从列表A中获取第2列和第3列与列表B相交的行? 预期结果: 解决方案不仅仅是“set(listA)&set(listB)”,因为列表的列数不同 谢谢你的时间 然后按我的要求打印结果。。。对于结果中的c1、c2、c3:打印c1、c2、c3。。。我说的对吗?然后按我的要求打印结果。。。对于结果中的c1、c2、c3:打印c1、c2、c3。。。我说得对吗? set_b = set(list_b) result = [x for

在我编写的代码中,我需要将两个水平列表相交,如:

listA: 列表B 如何从列表A中获取第2列和第3列与列表B相交的行?

预期结果: 解决方案不仅仅是“set(listA)&set(listB)”,因为列表的列数不同


谢谢你的时间

然后按我的要求打印结果。。。对于结果中的c1、c2、c3:打印c1、c2、c3。。。我说的对吗?然后按我的要求打印结果。。。对于结果中的c1、c2、c3:打印c1、c2、c3。。。我说得对吗?
set_b = set(list_b)
result = [x for x in list_a if (x[1], x[2]) in set_b]
('chr8', 'tagt')
('chr1', 'tttt')
('chr7', 'gtag')
('chr11','aaaa')
('chr9', 'atat')

#This lists are compounded by one str per line, wich it has a "/t" in the middle. 
#Also note that are in different order
name2   chr11   aaaa
name3   chr7    gtag
set_b = set(list_b)
result = [x for x in list_a if (x[1], x[2]) in set_b]