# How to use Select and MemberQ together with Map correctly?

I have a list with quite a few elements. Each element is a rule of the type vector-> number such as {1,2,3,4}->1.435 and all possible permutations of the vector of the rule are present, so I also have elements like {1,3,4,2}-> 1.325 and so on. I would like to select all elements of the list which have a permutation of a given vector as the first part of the rule. I'm trying to use Select together with MemberQand Apply. The code I wrote, and which is not working, is like this:

Select[list, MemberQ[#1, #2, 2] &] /@ Permutations[vector]


I guess I simply don't know how to Map with respect to the second argument of MemberQ, which in this case should be the permutations of the vector, and leave the first argument of the pure function MemberQ to be substituted by the elements of the list.

What does work, but I find somewhat ugly is

Table[Select[list, MemberQ[#, Permutations[vector][[i]],2] &],{i,1,Length[Permutations[vector]]}]


I could also write something using Module, but I want it to be more compact. Can you help me?

• try if Select[list, Function[x,MemberQ[x,#, 2] ]]& /@ Permutations[vector] or Function[p,Select[list,MemberQ[#,p,2]&]]/@Permutations[vector] gives what you need.
– kglr
Sep 22, 2021 at 16:08
• Thank you very much, @kglr. That works! Great! So, Function was the missing ingredient, I see now. Sep 22, 2021 at 16:21
• Looks like you're trying to nest pure functions: mathematica.stackexchange.com/questions/38393/… Sep 22, 2021 at 16:39
• Selecting members might be written as an Intersection Sep 23, 2021 at 8:07
• Yes, @march, I guess this is the same as was suggested by kglr. Sep 23, 2021 at 12:27