Message Boards Message Boards

GROUPS:

Total beginner, stuck on a simple problem

Posted 8 years ago
2566 Views
|
3 Replies
|
0 Total Likes
|

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!

POSTED BY: Fernando Benadon
3 Replies

Wonderful -- many thanks to both of you for helping me out with this!

POSTED BY: Fernando Benadon
Cases[{{1, 2}, {3, 5}, {2, 7}}, {x_, y_?(# >= 5 &)} :> {x, y}]
POSTED BY: l van Veen
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}}
POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract