select elements in a list
list = {{1, 11}, {2, 7}, {4, 2}, {7, 9}, {-2, 3}, {-1, 10}};
Select[list, #[[2]] > 8 &][[All, 1]]
{1, 7, -1}
OR using Pick
Pick[list[[All, 1]], UnitStep[list[[All, 2]] - 8], 1]
{1, 7, -1}
list = {{1, 11}, {2, 7}, {4, 2}, {7, 9}, {-2, 3}, {-1, 10}};
Cases[list, {a_, b_} /; b > 8 :> a]
(* {1, 7, -1} *)
What I'm doing above is to use Cases
to select only those sublists whose second element is greater than 8,
Cases[list, {a_, b_} /; b > 8]
(* {{1, 11}, {7, 9}, {-1, 10}} *)
The /;
notation defines a Condition
. Then I'm applying a :>
to make a replacement, in this case keeping only the first element, look at RuleDelayed
Pick[list[[All, 1]], # > 8 & /@ list[[All, 2]]]
or
Pick[#[[1]], # > 8 & /@ #[[2]]] &@Transpose[list]
{1, 7, -1}