I have a list of tuples: [(1, 2, 3), (2, 4)](the length of the list and tuples can vary), and I want to get all combinations containing at least one element from each tuple in the list, but also those combinations that contain more.
So, the result should be in this example:
[[1, 2, 3, 2, 4], [1, 2, 2, 4], [2, 3, 2, 4], [1, 2, 4], [2, 2, 4], [3, 2, 4], [1, 2, 3, 2], [1, 2, 3, 4], [1, 2, 2], [1, 2, 4], [2, 3, 2], [2, 3, 4], [1, 2], [1, 4], [2, 2], [2, 4], [3, 2], [3, 4]]
The smallest result should contain the number of elements equal to the number of tuples in the source list, the largest should contain all the elements present in the tuples.
The order of the elements does not matter, and duplicates should be ultimately eliminated (therefore, [1, 2, 3, 2, 4] = [1, 2, 3, 4]and should be the result only once, similarly [3, 2] = [2, 3], etc.), but I was thinking about sorting and / or eliminating duplicates after creating the entire list.
What is the best way to do this? Honestly, I don’t even know how to get started ...