Ask Your Question

Revision history [back]

A better data structure than lists to make intersectoins is set, so you can first transform your list of lists into a list of sets:

sage: Lset = [set(l) for l in L]
sage: Lset
[{'B', 'C', 'D', 'E'},
 {'A', 'C', 'D'},
 {'A', 'B', 'D', 'E'},
 {'A', 'B', 'C', 'D'}]

Then, you can pop the first set of your list to start with:

sage: s = Lset.pop()
sage: s
{'A', 'B', 'C', 'D'}
sage: Lset
[{'B', 'C', 'D', 'E'}, {'A', 'C', 'D'}, {'A', 'B', 'D', 'E'}]

Now you can intersect s with the remaining sets in Lset:

sage: s.intersection(*Lset)
{'D'}