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 MemberQ
and 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?
Select[list, Function[x,MemberQ[x,#, 2] ]]& /@ Permutations[vector]
orFunction[p,Select[list,MemberQ[#,p,2]&]]/@Permutations[vector]
gives what you need. $\endgroup$