One way:
selected = 10 < #[[1]] < 50 && #[[2]] < 6 & /@ m;
Pick[p, selected]
{{64, 33}, {77, 74}, {99, 5}}
Pick[list1, selected]
{2, 3, 4}
Of course, you can also use this on m
: Pick[m, selected]
.
To make your approach work you have to change a few things. As Edmund said, the &
needs to go inside the parenthesis. Then you need another set of parenthesis to surround the And
statement. You also need to set Heads -> False
or it will try to match your pattern with the heads of subexpressions, in this case List
. That will give errors because List
doesn't have a first and a second part. Finally you also need to specify at what level the subexpressions exist. All in all:
selected = Position[m, _?((10 < #[[1]] < 50) && (#[[2]] < 6) &), {1}, Heads -> False]
Extract[p, selected]
{{64, 33}, {77, 74}, {99, 5}}
Of course, this is based on the premise that you want to use the pattern in the question. As Edmund has shown, there are more appropriate patterns.