Skip to main content
added 213 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
ReplacePart[list0, {_, _, 2} :> Last[list2 = RotateLeft[list2]] ]
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Alternatively,

k = 1; ReplacePart[list0, {_, _, 2} :> list2[[k++]]]
 {{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Using Part assignment:

list0 = {{{12, 34}, {34, 56}}, {{56, 78}, {78, 91}}};
list1 = {{270, 271}, {272, 273}};

list0[[All, All, 2]] = list1;
list0
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

A few additional alternatives:

MapAt[Last[list2 = RotateLeft[list2]] &, {All, All, 2}] @ list0

k = 1; MapAt[list2[[k++]] &, {All, All, 2}] @ list0

SubsetMap[list2 &, {All, All, 2}] @ list0
ReplacePart[list0, {_, _, 2} :> Last[list2 = RotateLeft[list2]] ]
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Alternatively,

k = 1; ReplacePart[list0, {_, _, 2} :> list2[[k++]]]
 {{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Using Part assignment:

list0 = {{{12, 34}, {34, 56}}, {{56, 78}, {78, 91}}};
list1 = {{270, 271}, {272, 273}};

list0[[All, All, 2]] = list1;
list0
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}
ReplacePart[list0, {_, _, 2} :> Last[list2 = RotateLeft[list2]] ]
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Alternatively,

k = 1; ReplacePart[list0, {_, _, 2} :> list2[[k++]]]
 {{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Using Part assignment:

list0 = {{{12, 34}, {34, 56}}, {{56, 78}, {78, 91}}};
list1 = {{270, 271}, {272, 273}};

list0[[All, All, 2]] = list1;
list0
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

A few additional alternatives:

MapAt[Last[list2 = RotateLeft[list2]] &, {All, All, 2}] @ list0

k = 1; MapAt[list2[[k++]] &, {All, All, 2}] @ list0

SubsetMap[list2 &, {All, All, 2}] @ list0
added 135 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
ReplacePart[list0, {_, _, 2} :> Last[list2 = RotateLeft[list2]] ]
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Alternatively,

k = 1; ReplacePart[list0, {_, _, 2} :> list2[[k++]]]
 {{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Using Part assignment:

list0 = {{{12, 34}, {34, 56}}, {{56, 78}, {78, 91}}};
list1 = {{270, 271}, {272, 273}};

list0[[All, All, 2]] = list1;
list0
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}
ReplacePart[list0, {_, _, 2} :> Last[list2 = RotateLeft[list2]] ]
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Using Part assignment:

list0 = {{{12, 34}, {34, 56}}, {{56, 78}, {78, 91}}};
list1 = {{270, 271}, {272, 273}};

list0[[All, All, 2]] = list1;
list0
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}
ReplacePart[list0, {_, _, 2} :> Last[list2 = RotateLeft[list2]] ]
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Alternatively,

k = 1; ReplacePart[list0, {_, _, 2} :> list2[[k++]]]
 {{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Using Part assignment:

list0 = {{{12, 34}, {34, 56}}, {{56, 78}, {78, 91}}};
list1 = {{270, 271}, {272, 273}};

list0[[All, All, 2]] = list1;
list0
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}
added 232 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
ReplacePart[list0, {_, _, 2} :> Last[list2 = RotateLeft[list2]] ]
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Using Part assignment:

list0 = {{{12, 34}, {34, 56}}, {{56, 78}, {78, 91}}};
list1 = {{270, 271}, {272, 273}};

list0[[All, All, 2]] = list1;
list0
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}
ReplacePart[list0, {_, _, 2} :> Last[list2 = RotateLeft[list2]] ]
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}
ReplacePart[list0, {_, _, 2} :> Last[list2 = RotateLeft[list2]] ]
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}

Using Part assignment:

list0 = {{{12, 34}, {34, 56}}, {{56, 78}, {78, 91}}};
list1 = {{270, 271}, {272, 273}};

list0[[All, All, 2]] = list1;
list0
{{{12, 270}, {34, 271}}, {{56, 272}, {78, 273}}}
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Loading