If I have some list of lists of coordinates, i.e.


how can I count how many of the y coordinates in each of the lists has a value of 2 or greater? E.g. the first list has 3 y coordinates greater than or equal to 2, the second has 4 and the third has 3. I have tried

list1=list[[All, All, 2]]
Count[Map[list1], u_ /; u > 2]

but this isn't correctly separating my data by list.

  • 1
    $\begingroup$ Try this: Count[#, x_ /; x[[2]] >= 2, 1] & /@ list. $\endgroup$ – Anjan Kumar Mar 15 '18 at 15:44
  • $\begingroup$ That's great thanks! $\endgroup$ – JJH Mar 15 '18 at 15:52

Here's one way:


{3, 4, 3}


Here is another version using Count (another one is given in a comment):

Count[{_, _?(GreaterEqualThan[2])}] /@ list

And another one that I also like:

Count[{_, y_ /; y >= 2}] /@ list

Putting the condition close to the variable makes it clear what is happening.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.