I am trying to find a neat way of applying an operation to each list element, but do not know how to properly use multiple slots or whether it is actually possible to solve this with multiple slots. I am doing the following thing:
I have defined the following objects:
assoc1 = <|{a, b} -> 5, {c, d} -> 2, {e, f} -> -3|>;
lyst1 = {b, e, g};
lyst2 = {{b, e, g}, {a, b, c}};
Now, I want to select all entries in assoc1 whose key lists have a nonzero intersection with lyst1. This I can do in the following way:
KeySelect[assoc1, Intersection[lyst1, #] =!= {} &]
correctly getting the return:
<|{a, b} -> 5, {e, f} -> -3|>
And now the problem: Is there a way to elegantly do this for each list in lyst2 ? I know I could just use a for loop, but I was hoping for something shorter. I generally know how to apply a function to each element in lyst2 via "/@", but for that I would usually put a second Slot (=#) inside the Intersection function at the place where you see "lyst1" in my working example. I mean something like (knowing that this exact line does NOT do what I want):
KeySelect[assoc1, Intersection[#2, #1] =!= {} &] &/@ lyst2
where "#1" is the slot for each element in assoc1 whose key I am testing and "#2" is the slot used for looping over lyst2.
I do not know how to circumvent that or make it work with this second slot and would be very grateful for any suggestion!
f[v_]:=KeySelect[assoc1, Intersection[v, #] =!= {} &]
and thenMap[f[#]&,lyst2]
orf/@lyst2
and see if either of those are acceptable $\endgroup$