Skip to main content
6 of 16
another solution based on For
bmf
  • 17k
  • 2
  • 32
  • 68

We define

list = {x, x^2, x^3};
rules = {x -> 1, x -> 2, x -> 3};

and then

Inner[ReplaceAll, list, rules, List]
ReplaceAll @@@ Thread[{list, rules}]
Table[list[[i]] /. rules[[i]], {i, Length@rules}]
fnctn = #1 /. #2 & @@@ Transpose@({##}) &;

fnctn[list, rules]
MapIndexed[#^# &, Range@Length@list]
Last /@ Power[List @@@ rules, Range[Length@rules]]
  1. Anyone likes While? I don't but it works
Module[{return = {}, i = 1, end = Length@list},
 While[i <= end,
  AppendTo[return, list[[i]] /. rules[[i]]]; i++]; return]
  1. (I hate myself) using For because...why not?
Module[{return = {}}, For[
  i = 1, i <= Length@list, i++,
  AppendTo[return, list[[i]] /. rules[[i]]]];
 return]

all of the above give

{1, 4, 27}

bmf
  • 17k
  • 2
  • 32
  • 68