1
$\begingroup$

I have list of lists like this one:
list={{1, 9, 4, 7, 2}, {1, 4, 7, 1, 8}, {0, 5, 7, 2, 9}}
where every nested list have 5 elements.

I want to compare the third, fourth and fifth elements of each nested list and do the subtraction: the largest number minus the smallest number. The result should create a new list.

In my example, it should work like this:
in the first nested list {1, 9, 4, 7, 2} the largest value between the third, fourth and fifth elements is 7 and the smallest 2, subtraction 7-2=5. So 5 will be the first element in the new list with results. I want to do it with every nested list in my list of list.
For my example, the result will be:
result={5,7,7}

The problem is that I don't know how to do it. It's not just comparing the elements between nested lists or extracting specific elements from the lists (because I want to compare and subtract them first, then get the result). Please help!

$\endgroup$
9
  • 1
    $\begingroup$ Isn't the result supposed to be {5, 7, 7}? $\endgroup$ – Carl Woll Jun 11 at 22:38
  • 1
    $\begingroup$ Does (Max[#[[3;;5]]] - Min[#[[3;;5]]] &) /@ list work for you? $\endgroup$ – thorimur Jun 11 at 22:45
  • 1
    $\begingroup$ also I do think the result should be {5, 7, 7}, as 1 is the smallest element among the 3rd, 4th, and 5th elements of the second list, and 2 is the smallest among those elements in the last list $\endgroup$ – thorimur Jun 11 at 22:47
  • 1
    $\begingroup$ omg you're right, my fault! i'll change it $\endgroup$ – smolar Jun 11 at 22:51
  • 1
    $\begingroup$ now it turns out that I can't even count, all the more reason I need help $\endgroup$ – smolar Jun 11 at 22:54

Browse other questions tagged or ask your own question.