title: lambda function accessing outside variable
body: <p>I wanted to play around with anonymous functions so I decided to make a simple prime finder. Here it is:</p>
  <pre class="lang-py prettyprint-override"><code>tests = []
  end = int(1e2)
  i = 3
  while i &lt;= end:
      a = map(lambda f:f(i),tests)
      if True not in a:
          tests.append(lambda x:x%i==0)
          print i
      print tests
      print &quot;Test: &quot;+str(i)
      print str(a)
      i+=2
  </code></pre>
  <p>What I find however, is that the <code>i</code> in the <code>lambda x:x%i==0</code> is accessed each time, while i want it to be a literal number. how can I get it to become <code>lambda x:x%3==0</code> instead?</p>