title: Python closures with generator
body: <pre><code>def multipliers():
    return [lambda x : i * x for i in range(4)]
  
  print [m(2) for m in multipliers()]
  </code></pre>
  
  <p>I partially understood(which is dangerous) the reason that <code>i</code> is same for all functions because Python’s closures are late binding.</p>
  
  <p>The output is <code>[6, 6, 6, 6]</code> (not <code>[0, 2, 4, 6]</code> as I was expecting).</p>
  
  <hr>
  
  <p>I see that it works fine with a generator, my expected output is coming in below version.</p>
  
  <pre><code>def multipliers():
    return (lambda x : i * x for i in range(4))
  
  print [m(2) for m in multipliers()]
  </code></pre>
  
  <p>Any simple explanation why it is working in the below version ?</p>