I have the following lists:
l1 = {{"letter.a.a", "1"}, {"letter.b.b", "1"}, {"letter.c.c", "1"}, {"letter.d.d", "1"}, {"letter.e.e", "1"}, {"letter.f.f", "1"}};l2 = {{"f", 10}, {"c", 9}, {"e", 8}, {"b", 7}, {"d", 6}, {"a", 5}};
I want to replace the integers in l2
with "1"
s in l1
appropriately such that I get:
{{"letter.a.a", 5}, {"letter.b.b", 7}, {"letter.c.c", 9}, {"letter.d.d", 6}, {"letter.e.e", 8}, {"letter.f.f", 10}}
Given the strings in l1
and l2
are slightly different I wonder how one can do this?
Update: In a more complex system I have:
l1 = {{"Food.ALMOND.ALMONDCINNAMON", "1"}, {"Food.BLACK_CURRANT.BLACK_CURRANTCORN", "1"}, {"Food.BELL_PEPPER.BELL_PEPPERLIME", "1"}}l2 = {{"BLACK_CURRANTCORN", 4}, {"BELL_PEPPERLIME", 3}, {"ALMONDCINNAMON", 2}}
Here strings are words that need to be separated. How would one solve it for such lists? I think StringTake
method fails for this.