Why doesn't this python function with a dictionary named parameter and a default value apply the default value each time it's called?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1132941/least-astonishment-in-python-the-mutable-default-argument">“Least Astonishment” in Python: The Mutable Default Argument</a>  </p>
</blockquote>



<p>The following code illustrates the issue:</p>

<pre><code>def fn(param, named_param={}, another_named_param=1):
    named_param[param] = str(another_named_param)
    another_named_param += param
    return named_param

for i in range(0, 2):
    result = {}
    result = fn(i)

    print result

print

for i in range(0, 2):
    result = fn(i, named_param={})

    print result

print

result = fn(0)
print result
result = fn(1)
print result
</code></pre>

<p>Output:</p>

<pre><code>{0: '1'}
{0: '1', 1: '1'}

{0: '1'}
{1: '1'}

{0: '1', 1: '1'}
{0: '1', 1: '1'}
</code></pre>

<p>I expected the output of the 1st, 2nd loop and subsequent 2 single calls with param matching the values of the for loop would have the same textual output, but <code>fn</code> holds onto the value of <code>named_param</code> if not explicitly defaulted to an empty dictionary. Is functionality defined in the documentation?</p>
