# Position in nested list under criterium

I start from the following exemplary list, e.g.,

list = {{1, 2, 2}, {3, 2, 4}, {3, 5, 2}, {4, 5, 6}, {2, 5, 6}, {2, 5,
2}};


I learned how to to pick out elements of a specific column that fulfill a certain criterion by

In:  Select[list, #[[3]] > 2 &]
Out: {{3, 2, 4}, {4, 5, 6}, {2, 5, 6}}


Now I want to have the values and positions in the original list. I tried something like

In: Flatten[Position[list, _?(#[[3]] > 2 &)]]
Out: {2, 4, 5}


which actually gives me what I want, however with some error messages

"Part specification List[[3]] is longer than depth of object."


What is the correct way to do the pattern matching with Position? Certainly, I could ignore the error messages with Quiet.

Thank you for your help!

Flatten[Position[list, _?(#[[3]] > 2 &), 1, Heads -> False]]


{2, 4, 5}

• Are you still using v9? Do you have any ideas for this problem? Commented Nov 28, 2017 at 15:54
• @Szabolcs, still on v9:(
– kglr
Commented Nov 28, 2017 at 17:54

Try this:

Position[list, {x_, y_, z_} /; z > 2] // Flatten

(*  {2, 4, 5}  *)


Have fun!