title: How to use a DefaultDict with a lambda expression to make the default changeable?
body: <p>DefaultDicts are useful objects to be able to have a dictionary that can create new keys on the fly with a callable function used to define the default value. eg. Using <code>str</code> to make an empty string the default.</p>
  
  <pre><code>&gt;&gt;&gt; food = defaultdict(str)
  &gt;&gt;&gt; food['apple']
  ''
  </code></pre>
  
  <p>You can also use lambda to make an expression be the default value.</p>
  
  <pre><code>&gt;&gt;&gt; food = defaultdict(lambda: "No food")
  &gt;&gt;&gt; food['apple']
  'No food'
  </code></pre>
  
  <p>However you can't pass any parameters to this lambda function, that causes an error when it tries to be called, since you can't actually pass a parameter to the function.</p>
  
  <pre><code>&gt;&gt;&gt; food = defaultdict(lambda x: "{} food".format(x))
  &gt;&gt;&gt; food['apple']
  
  Traceback (most recent call last):
    File "&lt;pyshell#9&gt;", line 1, in &lt;module&gt;
      food['apple']
  TypeError: &lt;lambda&gt;() takes exactly 1 argument (0 given)
  </code></pre>
  
  <p>Even if you try to supply the parameter</p>
  
  <pre><code>&gt;&gt;&gt; food['apple'](12)
  
  Traceback (most recent call last):
    File "&lt;pyshell#9&gt;", line 1, in &lt;module&gt;
      food['apple']
  TypeError: &lt;lambda&gt;() takes exactly 1 argument (0 given)
  </code></pre>
  
  <p>How could these lambda functions be responsive rather than a rigid expression?</p>