| 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])
| 2 | No.2 Revision |
Since you talk about intersection, it is easier to convert lists to sets and use set.intersection function within function, like this:functools.reduce
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))
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.