Is there a way to riffle more than two lists?
{{a, b, c}, {1, 2, 3}, {x, y, z}} ~Flatten~ {2, 1}
{a, 1, x, b, 2, y, c, 3, z}
Riffle
does more than simply interleave lists of equal length. When the lists are not of the same length it will repeat elements from the second list, and it will also leave an element from the first list last position:
Riffle[{a, b, c, d, e, f}, {1, 2, 3}]
{a, 1, b, 2, c, 3, d, 1, e, 2, f}
How this would be generalized to multiple lists is not clear which I suspect is why Riffle
permits only two lists as input.
Perhaps you would find use, or at least interest, in the following construct:
multiRiffle[x : _List ..] :=
Module[{i = 1},
Fold[Riffle[##, {++i, -1, i}] &, {x}]
]
Now:
multiRiffle[{a, b, c}, {1, 2, 3}, {x, y, z}]
{a, 1, x, b, 2, y, c, 3, z}
But also:
multiRiffle[{a, b, c, d}, {1, 2}, {x, y, z}]
{a, 1, x, b, 2, y, c, 1, z, d, 2, x}
multiRiffle[{a, b}, {1, 2, 3, 4}, {x}]
{a, 1, x, b, 2, x}
I think these are closer in spirit to Riffle
than a simple transpose/flatten operation.
Flatten @ Transpose[{{a, b, c}, {1, 2, 3}, {x, y, z}}]
{a, 1, x, b, 2, y, c, 3, z}