Consider two lists of rules:
list1 = {"a" -> "apple", "b" -> "banana", "c" -> "cucumber"};
list2 = {"A" -> "pie", "B" -> "split", "C" -> "salad"};
I'm looking to come up with a way to "combine" these lists into a third list of rules Rule[key, val] in which key is a value from a rule taken from list1 and val is the value taken from the matching rule in list2. "Matching" here is subject to a custom criterion.
In this example, I want to get the list
{"apple" -> "pie", "banana" -> "split", "cucumber" -> "salad"}
where the combining criterion is that the keys consist of the same letter; that is, "a" and "A" satisfy some version of StringMatchQ[#1, #2, IgnoreCase -> True] &, for instance.
Is there a good way to do this?
For this particular example, this works (though I bet there's a neater way to do it):
With[
{list1 = {"a" -> "apple", "b" -> "banana", "c" -> "cucumber"},
list2 = {"A" -> "pie", "B" -> "split", "C" -> "salad"}},
(Reverse /@ list1) /. (list2 /. s_String :> ToLowerCase[s])
]
(* {"apple" -> "pie", "banana" -> "split", "cucumber" -> "salad"} *)
But in my more general use case, I'll have list1 and list2 with keys like {"x1", "y1", "z1"} and {"X-one", "Y-one", "Z-one"}, with the matching criterion that values to-be-Rule-ified are the ones whose corresponding keys contain 1 and one.
P.S. Sorry if the title is confusing, I wasn't quite sure how to word it.