python: dict of (lambda) functions
<p>I've experienced some strange behaviour when storing lambda functions into a dictionary: If you try to pass some default value to a function in a loop, only the last default value is being used.  </p>

<p>Here some minimal example:</p>

<pre><code>#!/usr/bin/env python
# coding: utf-8

def myfct(one_value, another_value):
    "do something with two int values"
    return one_value + another_value

fct_dict = {'add_{}'.format(number): (lambda x: myfct(x, number))
            for number in range(10)}

print('add_3(1): {}, id={}'.format(fct_dict['add_3'](1), id(fct_dict['add_3'])))
print('add_5(1): {}, id={}'.format(fct_dict['add_5'](1), id(fct_dict['add_5'])))
print('add_9(1): {}, id={}'.format(fct_dict['add_9'](1), id(fct_dict['add_9'])))
</code></pre>

<p>The output reads as follows</p>

<pre><code>add_3(1): 10, id=140421083875280
add_5(1): 10, id=140421083875520
add_9(1): 10, id=140421083876000
</code></pre>

<p>You get dissimilar functions (id not identical) but every function uses the same second argument.</p>

<p><strong>Can somebody explain what's going on?</strong></p>

<p>The same holds with python2, python3, pypy...</p>