I have a nested list and would like to permute the combinations among the list.
test = [[('a',)],
[('b', 'c'), ('d', 'e')],
[('f', 'g'), ('h', 'i'), ('j', 'k')],
[('l', 'm'), ('n', 'o'), ('p', 'q')]]
My expected output is like this:
[(('a',), ('b', 'c')),
(('a',), ('d', 'e')),
(('a',), ('f', 'g')),
(('a',), ('h', 'i')),
(('a',), ('j', 'k')),
(('b', 'c'), ('f', 'g')),
(('b', 'c'), ('h', 'i')),
(('b', 'c'), ('j', 'k')),
(('d', 'e'), ('f', 'g')),
(('d', 'e'), ('h', 'i')),
(('d', 'e'), ('j', 'k')),
(('a',), ('b', 'c'), ('f', 'g')),
(('a',), ('b', 'c'), ('h', 'i')),
(('a',), ('b', 'c'), ('j', 'k')),
(('a',), ('d', 'e'), ('f', 'g')),...,
(('a',), ('b', 'c'), ('f', 'g'), ('l', 'm')), ...]
To further elaborate, my ultimate goal is to permute among tuple lists from the permutation of 2 till the product permutation with the same logic that there is no self permutation. i.e. If there are 5 sublists in a nested list, I will permute from the combination of 2 to 5. Something like this [((),()),...,((),(),()),...,((),(),(),()),...,((),(),(),(),()),...]
I've tried list(itertools.combinations(itertools.chain(*test),2))
but I do not want the permutation among the sublists. For example, I want to exclude
((('b', 'c'), ('d', 'e')),
(('f', 'g'), ('h', 'i')),
(('f', 'g'), ('j', 'k')),
(('h', 'i'), ('j', 'k')),
(('f', 'g'), ('h', 'i'), ('j', 'k')),...)