Simplified and closer to your original question example
The First
value of each sublist is compared and the sublist with the largest first value is returned
l1 = {{1, a}, {2, b}};
MaximalBy[l1, First]
(* {{2, b}} *}
In your question q
is not a list of sublists, it has 3 levels of { }
. 3
is > 1
so the second sublist is returned.
l2 = {{{1, a}, {2, b}}, {{3, c}, {4, d}}};
MaximalBy[l2, First]
(* {{{3, c}, {4, d}}} *}
There is no pairwise comparison between the elements in the sublists and only the First
element of the sublist is considered. This does not change the result
l2 = {{{1, a}, {20, b}}, {{3, c}, {4, d}}}
MaximalBy[l2, First]
(* {{{3, c}, {4, d}}} *)
Regarding #
, &
, /@
, read this and this.