Find a value in a list given the a value contained in the first position of the list
One way could be
num = 89.9983 ;
Cases[list,{ num , x_} :> x]
(* {0.0000176696} *)
data//Pick[#[[All,2]], #[[All,1]], 89.9983]&
{0.0000176696}
%[[1]]
0.0000176696
If the use of Select
is required, maybe:
Select[list, #[[1]]==89.9983 &][[1,2]]
0.0000176696
(But IMO Pick
is a very powerful command in situations like this)
I’ve been really into using Extract
lately. So, here’s what I would do:
Extract[Position[list,{OrderlessPatternSequence[89.9983,___]}]][list][[-1,-1]]
(* 0.0000176696 *)
If you know the underlying list structure, that is why we use [[-1,-1]]
. If we don’t know the value, or, perhaps we only want to write one finder function, we can do the following:
FirstCase[list,{OrderlessPatternSequence[89.9983,v___]}:>v]
(* 0.0000176696 *)
Further generalization gives us:
valueCorrepondingTo[list_,num_]:=FirstCase[list,{OrderlessPatternSequence[num,v___]}:>v];
valueCorrepondingTo[list, 0.0000176696]
(* 89.9983 *)
I think this is really cool, this type of functionality and it is completely thanks to OrderlessPatternSequence
.