4
$\begingroup$

I have a list like this in Mathematica:

list1 = {{"A"},{"B","C"}} 

I am trying to output a second list that has the combinations of these elements but while maintaining the order, i.e., A should come first:

list2 = {{"A","B"},{"A","C"}} 

But, I am not sure how to do this efficiently.

Thanks.

$\endgroup$

2 Answers 2

7
$\begingroup$

You can use Distribute:

Distribute[list1, List] 

{{"A", "B"}, {"A", "C"}}

$\endgroup$
7
$\begingroup$
Tuples @ list1 

{{"A", "B"}, {"A", "C"}}

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.