Suppose that I have the following list, called list. list contains elements X, X1, X2, and X3:

list = {X, {X1, X2, X3}}

I would like a function that operates on list and gives the following output list:

{{X, X1}, {X, X2}, {X, X3}}

Is there a simple way to accomplish this with Thread, MapThread, Inner, Through, or the like? I feel like this should be simple, but I am having a lot of trouble coming up with a simple solution.

So far, I have only been able to come up with rather complicated solutions, such as

Transpose[{Table[#[[1]], {Length[#[[2]]]}], #[[2]]}] &@list

{{X, X1}, {X, X2}, {X, X3}}

  • 2
    $\begingroup$ Thread[{X,{X1,X2,X3}}] $\endgroup$
    – Coolwater
    Jan 8 '14 at 18:07
  • 2
    $\begingroup$ I recommed Tuples: Tuples[{{X}, {X1, X2, X3}}], for another solutions and benchmarks see this post. $\endgroup$
    – Artes
    Jan 8 '14 at 18:20

Browse other questions tagged or ask your own question.