Riffle multiple lists together
As mentioned in the comments, Tuples[]
does it:
Tuples[{{a, b}, {1, 2, 3, 4}}]
{{a, 1}, {a, 2}, {a, 3}, {a, 4}, {b, 1}, {b, 2}, {b, 3}, {b, 4}}
Before Tuples[]
became a built-in function, one used to use Outer[]
for the task, in conjunction with Flatten[]
:
Flatten[Outer[List, {a, b}, {1, 2, 3, 4}], 1]
There is also: Distribute
Distribute[{{a, b}, {1, 2, 3, 4}}, List]
{{a, 1}, {a, 2}, {a, 3}, {a, 4}, {b, 1}, {b, 2}, {b, 3}, {b, 4}}