Reputation: 3038
At the code I'm writing I need to intersect two horizontal list like:
('name1','chr1', 'aatt')
('name2','chr11', 'aaga')
('name2','chr11', 'aaaa')
('name3','chr7', 'gtag')
('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
How can I get the lines from the listA whose columns 2 and 3 intersect with the listB?
name2 chr11 aaaa
name3 chr7 gtag
The solution is not just "set(listA)&set(listB)" because the list have different number of columns
thanks for your time!
Upvotes: 0
Views: 152
Reputation: 601529
set_b = set(list_b)
result = [x for x in list_a if (x[1], x[2]) in set_b]
Upvotes: 3