【发布时间】:2011-05-16 17:57:52
【问题描述】:
在我正在编写的代码中,我需要将两个水平列表相交,例如:
列表A:
('name1','chr1', 'aatt')
('name2','chr11', 'aaga')
('name2','chr11', 'aaaa')
('name3','chr7', 'gtag')
列表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
如何从 listA 中获取第 2 列和第 3 列与 listB 相交的行?
想要的结果:
name2 chr11 aaaa
name3 chr7 gtag
解决方案不仅仅是“set(listA)&set(listB)”,因为列表的列数不同
感谢您的宝贵时间!
【问题讨论】:
标签: python list intersection