6

I couldn't find a similar question so I decided to ask this one. I have a nested list with many sublists of equal length. To make things easier let's say it's like that:

list={{2,1,7},{3,9,5},{4,8,6}}

I'd like to get a list of last elements from each sublist, in this case:

{7,5,6}

I'm not sure whether i should think of a pattern to do this or is there a simpler way?

Wojciech
  • 398
  • 4
  • 15

1 Answers1

9

It is

list = {{2, 1, 7}, {3, 9, 5}, {4, 8, 6}};
list[[All, -1]]
(* {7, 5, 6} *)

or

Last /@ list
(* {7, 5, 6} *)
halirutan
  • 112,764
  • 7
  • 263
  • 474