List to list transformation rules

GROUPS:
 Hello, Here is an oversimplified list : {x,x,x} and a list of transformation rules : {x->a, x->b, x->c}. What I need : to apply the first rule to the first element, the second rule to the second element and so on. Expected result : {a,b,c}A neat way to do this ?Thanks in advance, Andre
4 years ago
9 Replies
 Frank Kampas 1 Vote In[11]:= Inner[ReplaceAll, {x, x, x}, {x -> a, x -> b, x -> c}, List] Out[11]= {a, b, c} 
4 years ago
 Frank Kampas 1 Vote Another approach In[12]:= MapThread[ReplaceAll, {{x, x, x}, {x -> a, x -> b, x -> c}}] Out[12]= {a, b, c} 
4 years ago
 Andre Hautot 1 Vote The first solution sligthly less time-consuming, Many thanks, Andre
4 years ago
 Hello Andre, this is a little faster approach: In[11]:= ReplaceAll[{x, x, x}, {x__} -> { a, b, c}] Out[11]= {a, b, c} Here, the result is independent from the list (input) because of _ _ (blank sequence). For example: In[12]:= ReplaceAll[{x, y, z}, {x__} -> { a, b, c}] Out[12]= {a, b, c} 
4 years ago
 If the oversimplified list is always of that form then a simple transformation is: In[32]:= x /. Partition[{x -> a, x -> b, x -> c}, 1] Out[32]= {a, b, c} 
4 years ago
 Or if there's no transformation at all: {x -> a, x -> b, x -> c}[[All, 2]] {a, b, c} 
 What about just removing all items from one list from another list? list1 = {"item1", "item2", "item3", "item4"} list2 = {"item1", "item2", "item5", "item6"} here are my poor guesses: ReplaceAll[list1,list2] or DeleteCases[list1, list2] expected result: Out[165]= {item3, item4} 
 Here is a solution I built from the help I got in another thread. Hope it is useful. I thought it was!It allows you to create a list by filtering for both included items and excluded items. You can remove all items from one list from a second list and also exclude items from a third list. bigList = {"item1", "item2", "item3", "item4", "item6", "item7", "item8", "item9"}; excludedElements = {"item1", "item2", "item5", "item6"}; includedElements = {"item8", "item9"}; Select[Select[bigList, StringFreeQ[#, excludedElements] &], ! StringFreeQ[#, includedElements] &] Out[14]={"item8", "item9"}