Hi -- I'm teaching myself Mathematica to work on music theory projects. I'm hoping someone can help me figure out the following. From a list such as {{1,2}, {3,5}, {2,7}}, how do I select pairs whose second element is greater than (say) 5? I can't figure out how to make Cases or Select work with nested lists. Thank you!
In[1]:= l = {{1, 2}, {3, 5}, {2, 7}}; In[2]:= Select[l, #[[2]] > 5 &] Out[2]= {{2, 7}} In[3]:= Cases[l, {_, x_ /; x > 5}] Out[3]= {{2, 7}}
Cases[{{1, 2}, {3, 5}, {2, 7}}, {x_, y_?(# >= 5 &)} :> {x, y}]
Wonderful -- many thanks to both of you for helping me out with this!