I have a list say lis1 = [1,2,3]
and a list of subset of above list say
lis2 = [[1,2],[2,3],[3],[1],[2]]
I want to generate all combinations of lis2 such that all items of lis1 should present in the combination.
For eg. this is a valid combinations
one such combination is [[1,2],[2,3]]
(all items of lis1
i.e [1,2,3]
is present in it)
whereas this is not
[[1,2],[1],[2]] # (3 is not present in it)
What I did was generated powerset of lis2 via this function
from itertools import chain, combinations
def powerset(iterable):
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(1,len(s)+1))
But as obvious the returning set contain combinations which are of type
[[1,2],[1],[2]] # (3 is not present in it)
How do I check for the combinations which contain all the item of lis1