Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Since you talk about intersection, it is easier to convert lists to sets and use set.intersection function within functools.reduce like this:

import functools

L=[["B", "C", "D", "E"],["A", "C", "D"],["A", "B","D", "E"], ["A", "B","D", "C"] ]
S=[set(Li) for Li in L]
functools.reduce(set.intersection,S[1:],S[0])

Since you talk about intersection, it is easier to convert lists to sets and use set.intersection function within functools.reduce function, like this:

import functools

L=[["B", "C", "D", "E"],["A", "C", "D"],["A", "B","D", "E"], ["A", "B","D", "C"] ]
S=[set(Li) set.intersection(*(set(Li) for Li in L]
functools.reduce(set.intersection,S[1:],S[0])
L))