# Doing combinations of sub-sublists

To create a list of all the possible combinations of a sublist. I have a list, somewhat resembling the following format:

{{{a1, a2}, {b1}}, {{a1, a2}, {c1, c2}}, {{a1, a2}, {c1, c2}, {d1, d2}}}


I'm trying to get Mathematica to generate a list that is all the combinations of the contents of these sublists. So I'd get

{{a1, b1}, {a2, b1}, {a1, c1}, {a1, c2}, {a2, c1}, {a2, c2},
{a1, c1, d1}, {a1, c1, d2}, {a1 ,c2 ,d1}, {a1, c2, d2}, {a2, c1, d1},
{a2, c1, d2}, {a2, c2, d1}, {a2, c2, d2}}


It was suggested that I use a nested For loop to accomplish this, but I'm not entirely sure that would be the most efficient way to go about this.

Is there a clever way I could apply some combination of the mathematica list functions to accomplish this goal?

• Welcome Andrew. Please look at the help section, especially the section about how to format your question. Commented Feb 20, 2017 at 2:20
• Catenate[Tuples /@ list]
– yode
Commented Feb 20, 2017 at 2:43

l = {{{a1, a2}, {b1}}, {{a1, a2}, {c1, c2}}, {{a1, a2}, {c1, c2}, {d1, d2}}};