Skip to main content
Formatted code
Source Link
MarcoB
  • 67.7k
  • 18
  • 96
  • 198
xy = {{x1, y1}, {x2, y2}, ...}
z = {z1, z2, ...}
xyz = Partition[Flatten[Riffle[xy, z]], 3]

and you're done. RiffleRiffle also works with just one z-value,: it'll do exactly what your question wasyou asked, after re-reading your question more carefully.

Explanation:

First, Riffle[list1,list2 or element, so just z1 works, too]Riffle[list1, list2 **or** element, so just z1 works, too] makes

{ {x1, y1}, z1, {x2, y2}, z2, ...}

then, Flatten[list(s)]Flatten[list] makes

{ x1, y1, z1, x2, y2, z2, ... }

finally, Partition[list,n]Partition[list, 3] turns it into

{ {x1, y1, z1}, {x2, y2, z2}, ...}
xy = {{x1,y1},{x2,y2},..}
z = {z1,z2,..}
xyz = Partition[Flatten[Riffle[xy,z]],3]

and you're done. Riffle also works with just one z-value, it'll do exactly what your question was, after re-reading your question more carefully.

Explanation:

First, Riffle[list1,list2 or element, so just z1 works, too] makes

{ {x1,y1}, z1, {x2,y2}, z2, ..}

then, Flatten[list(s)] makes

{ x1,y1,z1,x2,y2,z2,.. }

finally, Partition[list,n] turns it into

{ {x1,y1,z1}, {x2,y2,z2}, ...}
xy = {{x1, y1}, {x2, y2}, ...}
z = {z1, z2, ...}
xyz = Partition[Flatten[Riffle[xy, z]], 3]

and you're done. Riffle also works with just one z-value: it'll do exactly what you asked, after re-reading your question more carefully.

Explanation:

First, Riffle[list1, list2 **or** element, so just z1 works, too] makes

{ {x1, y1}, z1, {x2, y2}, z2, ...}

then, Flatten[list] makes

{ x1, y1, z1, x2, y2, z2, ... }

finally, Partition[list, 3] turns it into

{ {x1, y1, z1}, {x2, y2, z2}, ...}
Spellin
Source Link
xy = {{x1,y1},{x2,y2},..}
z = {z1,z2,..}
xyz = Partition[Flatten[Riffle[xy,z]],3]

and you're done. Riffle also works with just one z-value, it'll do exactly what your question was, after re-reading your question more carefully.

Explanation:

First, Riffle[list1,list2]list2 or element, so just z1 works, too] makes

{ {x1,y1}, z1, {x2,y2}, z2, ..}

then, Flatten[list(s)] makes

{ x1,y1,z1,x2,y2,z2,.. }

finally, Partition[list,n] turns it into

{ {x1,y1,z1}, {x2,y2,z2}, ...}
xy = {{x1,y1},{x2,y2},..}
z = {z1,z2,..}
xyz = Partition[Flatten[Riffle[xy,z]],3]

and you're done. Riffle also works with just one z-value, it'll do exactly what your question was, after re-reading your question more carefully.

Explanation:

First, Riffle[list1,list2] makes

{ {x1,y1}, z1, {x2,y2}, z2, ..}

then, Flatten[list(s)] makes

{ x1,y1,z1,x2,y2,z2,.. }

finally, Partition[list,n] turns it into

{ {x1,y1,z1}, {x2,y2,z2}, ...}
xy = {{x1,y1},{x2,y2},..}
z = {z1,z2,..}
xyz = Partition[Flatten[Riffle[xy,z]],3]

and you're done. Riffle also works with just one z-value, it'll do exactly what your question was, after re-reading your question more carefully.

Explanation:

First, Riffle[list1,list2 or element, so just z1 works, too] makes

{ {x1,y1}, z1, {x2,y2}, z2, ..}

then, Flatten[list(s)] makes

{ x1,y1,z1,x2,y2,z2,.. }

finally, Partition[list,n] turns it into

{ {x1,y1,z1}, {x2,y2,z2}, ...}
Changed Join to Flatten. Join be damned! Useless.
Source Link
xy = {{x1,y1},{x2,y2},..}
z = {z1,z2,..}
xyz = Partition[Join[Riffle[xyPartition[Flatten[Riffle[xy,z]],3]

and you're done. Riffle also works with just one z-value, it'll do exactly what your question was, after re-reading your question more carefully.

Explanation:

First, Riffle[list1,list2] makes

{ {x1,y1}, z1, {x2,y2}, z2, ..}

then, Join[listFlatten[list(s)] makes

{ x1,y1,z1,x2,y2,z2,.. }

finally, Partition[list,n] turns it into

{ {x1,y1,z1}, {x2,y2,z2}, ...}
xy = {{x1,y1},{x2,y2},..}
z = {z1,z2,..}
xyz = Partition[Join[Riffle[xy,z]],3]

and you're done.

Explanation:

First, Riffle[list1,list2] makes

{ {x1,y1}, z1, {x2,y2}, z2, ..}

then, Join[list(s)] makes

{ x1,y1,z1,x2,y2,z2,.. }

finally, Partition[list,n] turns it into

{ {x1,y1,z1}, {x2,y2,z2}, ...}
xy = {{x1,y1},{x2,y2},..}
z = {z1,z2,..}
xyz = Partition[Flatten[Riffle[xy,z]],3]

and you're done. Riffle also works with just one z-value, it'll do exactly what your question was, after re-reading your question more carefully.

Explanation:

First, Riffle[list1,list2] makes

{ {x1,y1}, z1, {x2,y2}, z2, ..}

then, Flatten[list(s)] makes

{ x1,y1,z1,x2,y2,z2,.. }

finally, Partition[list,n] turns it into

{ {x1,y1,z1}, {x2,y2,z2}, ...}
Explanation of the oneliner
Source Link
Loading
Source Link
Loading