Skip to main content
added 125 characters in body
Source Link
E. Chan-López
  • 31.2k
  • 3
  • 29
  • 50

Just another way, using Cases, DeleteElements and Function:

Map[Function[{y}, Join[DeleteElements[y, {_, x_} :> x], Cases[y, {_, x_} :> x]]], list]
(*{{{1, 1, 1, 1}, 0.861155}, {{1, 1, 1, 11}, 0.512393}, {{1, 1, 1, 21}, 0.410614}, {{1, 1, 1, 31}, 0.351969}}*)

Or using MapAt:

Transpose@MapAt[#[[All, 2]] &, Transpose@list, {2}]
(*{{{1, 1, 1, 1}, 0.861155}, {{1, 1, 1, 11}, 0.512393}, {{1, 1, 1, 21}, 0.410614}, {{1, 1, 1, 31}, 0.351969}}*)

Thanks to @eldo for the following shorter version using MapAt:

MapAt[Last, {All, 2}]@list

(*same result*)

Just another way, using Cases, DeleteElements and Function:

Map[Function[{y}, Join[DeleteElements[y, {_, x_} :> x], Cases[y, {_, x_} :> x]]], list]
(*{{{1, 1, 1, 1}, 0.861155}, {{1, 1, 1, 11}, 0.512393}, {{1, 1, 1, 21}, 0.410614}, {{1, 1, 1, 31}, 0.351969}}*)

Or using MapAt:

Transpose@MapAt[#[[All, 2]] &, Transpose@list, {2}]
(*{{{1, 1, 1, 1}, 0.861155}, {{1, 1, 1, 11}, 0.512393}, {{1, 1, 1, 21}, 0.410614}, {{1, 1, 1, 31}, 0.351969}}*)

Just another way, using Cases, DeleteElements and Function:

Map[Function[{y}, Join[DeleteElements[y, {_, x_} :> x], Cases[y, {_, x_} :> x]]], list]
(*{{{1, 1, 1, 1}, 0.861155}, {{1, 1, 1, 11}, 0.512393}, {{1, 1, 1, 21}, 0.410614}, {{1, 1, 1, 31}, 0.351969}}*)

Or using MapAt:

Transpose@MapAt[#[[All, 2]] &, Transpose@list, {2}]
(*{{{1, 1, 1, 1}, 0.861155}, {{1, 1, 1, 11}, 0.512393}, {{1, 1, 1, 21}, 0.410614}, {{1, 1, 1, 31}, 0.351969}}*)

Thanks to @eldo for the following shorter version using MapAt:

MapAt[Last, {All, 2}]@list

(*same result*)
added 197 characters in body
Source Link
E. Chan-López
  • 31.2k
  • 3
  • 29
  • 50

Just another way, using Cases, DeleteElements and Function:

Map[Function[{y}, Join[DeleteElements[y, {_, x_} :> x], Cases[y, {_, x_} :> x]]], list]
(*{{{1, 1, 1, 1}, 0.861155}, {{1, 1, 1, 11}, 0.512393}, {{1, 1, 1, 21}, 0.410614}, {{1, 1, 1, 31}, 0.351969}}*)

Or using MapAt:

Transpose@MapAt[#[[All, 2]] &, Transpose@list, {2}]
(*{{{1, 1, 1, 1}, 0.861155}, {{1, 1, 1, 11}, 0.512393}, {{1, 1, 1, 21}, 0.410614}, {{1, 1, 1, 31}, 0.351969}}*)

Just another way, using Cases, DeleteElements and Function:

Map[Function[{y}, Join[DeleteElements[y, {_, x_} :> x], Cases[y, {_, x_} :> x]]], list]
(*{{{1, 1, 1, 1}, 0.861155}, {{1, 1, 1, 11}, 0.512393}, {{1, 1, 1, 21}, 0.410614}, {{1, 1, 1, 31}, 0.351969}}*)

Just another way, using Cases, DeleteElements and Function:

Map[Function[{y}, Join[DeleteElements[y, {_, x_} :> x], Cases[y, {_, x_} :> x]]], list]
(*{{{1, 1, 1, 1}, 0.861155}, {{1, 1, 1, 11}, 0.512393}, {{1, 1, 1, 21}, 0.410614}, {{1, 1, 1, 31}, 0.351969}}*)

Or using MapAt:

Transpose@MapAt[#[[All, 2]] &, Transpose@list, {2}]
(*{{{1, 1, 1, 1}, 0.861155}, {{1, 1, 1, 11}, 0.512393}, {{1, 1, 1, 21}, 0.410614}, {{1, 1, 1, 31}, 0.351969}}*)
Source Link
E. Chan-López
  • 31.2k
  • 3
  • 29
  • 50

Just another way, using Cases, DeleteElements and Function:

Map[Function[{y}, Join[DeleteElements[y, {_, x_} :> x], Cases[y, {_, x_} :> x]]], list]
(*{{{1, 1, 1, 1}, 0.861155}, {{1, 1, 1, 11}, 0.512393}, {{1, 1, 1, 21}, 0.410614}, {{1, 1, 1, 31}, 0.351969}}*)