# How can I rearrange my list?

I have this list,

  {{a}, {i1, i2, i3}, {1, 2, 3}}


which I want to rearrange to this:

  {{1, i1, a}, {2, i2, a}, {3, i3, a}}


It is for use with ListPlot3D[]. How can I do it?

• Transpose@Reverse[PadRight[#, 3, a] & /@ list] May 27, 2021 at 2:49
• @BobHanlon That will work on the OP's MWE (at least I assume it's an MWE...), but not on longer examples, e.g., list={{a}, {i1, i2, i3, i4}, {1, 2, 3, 4}}. May 27, 2021 at 5:41
• @theorist - more generally, Transpose@ Reverse[PadRight[#, Length[list[[-1]]], list[[1, 1]]] & /@ list] May 27, 2021 at 5:56
• @BobHanlon Another approach using padding: ArrayPad[Thread@Reverse@Rest@list, {{0}, {0, 1}}, First@list] May 27, 2021 at 6:05

A crappy attempt:

{{a}, {i1, i2, i3}, {1, 2, 3}} /. {a_, b_, c_} :>
Thread[List[c, b, x]] /. x :> a

• Could you please tell me what this symbol ( :> ) is? I couldn't find it May 27, 2021 at 17:20
• @DelaramNematollahi See here: Rule Delayed May 27, 2021 at 18:21
• @Charmbracelet Thank you May 27, 2021 at 19:05
Thread[{#3,#2,Sequence@@#1}]&@@lst


{{1, i1, a}, {2, i2, a}, {3, i3, a}}

Slightly shorter

Thread[{#3,#2,First@#1}]&@@lst

list = {{a}, {i1, i2, i3}, {1, 2, 3}}

f = Thread @ Reverse @ PadRight[#, Automatic, #] &;


Examples:

lst1 = {{a}, {i1, i2, i3}, {1, 2, 3}};

f @ lst1

 {{1, i1, a}, {2, i2, a}, {3, i3, a}}

lst2 = {{a}, {i1, i2, i3}, {x, y}, {1, 2, 3, 4}};

f @ lst2

 {{1, x, i1, a}, {2, y, i2, a}, {3, x, i3, a}, {4, y, i1, a}}

• I think Transpose is a little more natural/accessible here than Thread. May 28, 2021 at 7:00