Skip to main content
Mainly title
Source Link
Jacob Akkerboom
  • 12.2k
  • 46
  • 82

Merging totwo lists by prepending elements

Being a newcomer to MathematicaMathematica, I have thisthe following question:.

Given

x = Range@9~Partition~3;

and

y = {a, b, c};

I want to combine xx and yy so that

result = {{a, 1, 2, 3}, {b, 4, 5, 6}, {c, 7, 8, 9}};

I have written

MapPrepend[a_, b_] := Prepend[a[[#]], b[[#]]] & /@ Range@Length@b

which does the job, but I wonder if there are other, more functional solutions?

Probably this question has already been answered. In this case it would be very nice if you just would direct me to the links.

Merging to lists

Being a newcomer to Mathematica, I have this question:

Given

x = Range@9~Partition~3;

and

y = {a, b, c};

I want to combine x and y so that

result = {{a, 1, 2, 3}, {b, 4, 5, 6}, {c, 7, 8, 9}};

I have written

MapPrepend[a_, b_] := Prepend[a[[#]], b[[#]]] & /@ Range@Length@b

which does the job, but I wonder if there are other, more functional solutions?

Probably this question has already been answered. In this case it would be very nice if you just would direct me to the links.

Merging two lists by prepending elements

Being a newcomer to Mathematica, I have the following question.

Given

x = Range@9~Partition~3;

and

y = {a, b, c};

I want to combine x and y so that

result = {{a, 1, 2, 3}, {b, 4, 5, 6}, {c, 7, 8, 9}};

I have written

MapPrepend[a_, b_] := Prepend[a[[#]], b[[#]]] & /@ Range@Length@b

which does the job, but I wonder if there are other, more functional solutions?

Probably this question has already been answered. In this case it would be very nice if you just would direct me to the links.

Source Link
eldo
  • 83.1k
  • 6
  • 72
  • 202

Merging to lists

Being a newcomer to Mathematica, I have this question:

Given

x = Range@9~Partition~3;

and

y = {a, b, c};

I want to combine x and y so that

result = {{a, 1, 2, 3}, {b, 4, 5, 6}, {c, 7, 8, 9}};

I have written

MapPrepend[a_, b_] := Prepend[a[[#]], b[[#]]] & /@ Range@Length@b

which does the job, but I wonder if there are other, more functional solutions?

Probably this question has already been answered. In this case it would be very nice if you just would direct me to the links.