title: empty dictionary as default value for keyword argument in python function: dictionary seems to not be initialised to {} on subsequent calls?
body: <p>Here's a function. My intent is to use keyword argument defaults to make the dictionary an empty dictionary if it is not supplied.</p>
  
  <pre><code>&gt;&gt;&gt; def f( i, d={}, x=3 ) :
  ...     d[i] = i*i
  ...     x += i
  ...     return x, d
  ... 
  &gt;&gt;&gt; f( 2 )
  (5, {2: 4})
  </code></pre>
  
  <p>But when I next call f, I get:</p>
  
  <pre><code>&gt;&gt;&gt; f(3)
  (6, {2: 4, 3: 9})
  </code></pre>
  
  <p>It looks like the keyword argument d at the second call does not point to an empty dictionary, but rather to the dictionary as it was left at the end of the preceding call.  The number x is reset to three on each call.</p>
  
  <p>Now I can work around this, but I would like your help understanding this.  I believed that keyword arguments are in the local scope of the function, and would be deleted once the function returned. (Excuse and correct my terminology if I am being imprecise.)</p>
  
  <p>So the local value pointed to by the name d should be deleted, and on the next call, if I don't supply the keyword argument d, then d should be set to the <code>default {}</code>.   But as you can see, d is being set to the dictionary that d pointed to in the preceding call.</p>
  
  <p>What is going on?</p>
  
  <p>Is the <code>literal {}</code> in the def line in the enclosing scope?</p>
  
  <p>This behavior is seen in 2.5, 2.6 and 3.1.</p>