title: avoiding nested for loops python
body: <p>I have a function which takes in expressions and replaces the variables with all the permutations of the values that I am using as inputs. This is my code that I have tested and works, however after looking through SO, people have said that nested for loops are a bad idea however I am unsure as to how to make this more efficient. Could somebody help? Thanks. </p>
  
  <pre><code>def replaceVar(expression):
  
      eval_list = list()
  
      a = [1, 8, 12, 13]
      b = [1, 2, 3, 4]
      c = [5, 9, 2, 7]
  
      for i in expression:
          first_eval = [i.replace("a", str(j)) for j in a]
          tmp = list()
          for k in first_eval:
              snd_eval = [k.replace("b", str(l)) for l in b]
              tmp2 = list()
              for m in snd_eval:
                  trd_eval = [m.replace("c", str(n)) for n in c]
                  tmp2.append(trd_eval)
              tmp.append(tmp2)
          eval_list.append(tmp)
      print(eval_list)
      return eval_list
  
  print(replaceVar(['b-16+(c-(a+11))', 'a-(c-5)+a-b-10']))
  </code></pre>