# How to further process a 2 dimensional list created with tuples

I created with

Tuples[{{USD, EUR, JPY}, {UP, DOWN}}]

the following result:

{{USD, UP}, {USD, DOWN}, {EUR, UP}, {EUR, DOWN}, {JPY, UP}, {JPY, DOWN}}

I want to further have a 3 dimensional list of all combinations - but the same currency does not appear twice. Example output

{{{USD, UP}, {EUR, UP}, {JPY, UP}}, {{USD, UP}, {EUR, UP}, {JPY, DOWN}}, {{USD, UP}, {EUR, DOWN}, {JPY, UP}}, {{USD, UP}, {EUR, DOWN}, {JPY, DOWN}}, ... {{USD, DOWN}, {EUR, DOWN}, {JPY, DOWN}}}

Is there a simple way to do it?

Here is one way:

Tuples@Outer[List, {USD, EUR, JPY}, {UP, DOWN}]
(*
{{{USD, UP}, {EUR, UP}, {JPY, UP}},
{{USD, UP}, {EUR, UP}, {JPY, DOWN}},
{{USD, UP}, {EUR, DOWN}, {JPY, UP}},
{{USD, UP}, {EUR, DOWN}, {JPY, DOWN}},
{{USD, DOWN}, {EUR, UP}, {JPY, UP}},
{{USD, DOWN}, {EUR, UP}, {JPY, DOWN}},
{{USD, DOWN}, {EUR, DOWN}, {JPY, UP}},
{{USD, DOWN}, {EUR, DOWN}, {JPY, DOWN}}}
*)

• I can't beat that. I tried. :-) – Mr.Wizard Jul 18 '14 at 13:12
• @Mr.Wizard Thanks! – Michael E2 Jul 18 '14 at 13:19

Yes, one way is to use Tuples again after some judicious partitioning:

Tuples[Partition[Tuples[{{"USD", "EUR", "JPY"}, {"UP", "DOWN"}}], 2]]


Note the 2 is the length of the second set in the original Tuples so you could write your own function:

myTuples[list1_List, list2_List] := Tuples[Partition[Tuples[{list1, list2}], Length[list2]]]