I would like to find the intersection between nested lists while maintaining the order.
taxa = [['E_pyrifoliae_Ep1_96', 'Bacteria', 'Proteobacteria', 'Gammaproteobacteria', 'Enterobacteriales', 'Enterobacteriaceae', 'Erwinia'],
['E_amylovora_CFBP1430', 'Bacteria', 'Proteobacteria', 'Gammaproteobacteria', 'Enterobacteriales', 'Enterobacteriaceae', 'Erwinia'],
['E_amylovora_ATCC49946', 'Bacteria', 'Proteobacteria', 'Gammaproteobacteria', 'Enterobacteriales', 'Enterobacteriaceae', 'Erwinia']]
To find the intersection I have:
set.intersection(*map(set, taxa))
or
set(taxa[0]).intersection(*taxa)
but the original order is not kept.
set(['Erwinia', 'Gammaproteobacteria', 'Enterobacteriaceae', 'Enterobacteriales', 'Proteobacteria', 'Bacteria'])
Basically, what I need to do is find the last common element between the nested lists (they are taxanomic classifications ). So I don't need to find all the intersections, just the last one or all of them when I can just call on the last entry.
intersection_lst[-1]
In this instance I want the output to be 'Erwinia'.
Thanks for your help.