Python 如何在两个水平列表之间相交一系列列?
在我编写的代码中,我需要将两个水平列表相交,如: listA: 列表B 如何从列表A中获取第2列和第3列与列表B相交的行? 预期结果: 解决方案不仅仅是“set(listA)&set(listB)”,因为列表的列数不同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
谢谢你的时间 然后按我的要求打印结果。。。对于结果中的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]