My apologies if this has been asked before, but I'm trying to implement the itertools permutations and combinations tools, but I can't get the packages to give the precise output I'm looking for. For instance, with the input:
[2,3,5,7,11,13,17,19]
I wish to output all possible ways of 'splitting' the list into tuples (not necessarily keeping the order of the given list):
[(2,3)(5)(7)(11)(13)(17)(19), (2,5)(3)(7)(11)(13)(17)(19), ..., (2,3,7)(5,11,17)(13)(19), ..., (2,3,5,7,11)(13,17,19)]
In other words, you can have more than one combination per element in the new list.
However I've got the following code (not claiming authorship to this line, though) to output all the isolated tuples:
[a for l in range(2,5) for a in itertools.combinations([2,3,5,7,11,13,17,19], l)].
i.e.:
[(2, 3), (2, 5), (2, 7), (2, 11), ..., (7, 13, 17, 19), (11, 13, 17, 19)]
Is there a function that can be used to give the desired output? (i.e. all possible groupings within all elements
Thank you!