title: Most pythonic way of assigning keyword arguments using a variable as keyword?
body: <p>What is <strong>the most pythonic way</strong> to get around the following problem? From the interactive shell:</p>
  
  <pre><code>&gt;&gt;&gt; def f(a=False):
  ...     if a:
  ...         return 'a was True'
  ...     return 'a was False'
  ... 
  &gt;&gt;&gt; f(a=True)
  'a was True'
  &gt;&gt;&gt; kw = 'a'
  &gt;&gt;&gt; val = True
  &gt;&gt;&gt; f(kw=val)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  TypeError: f() got an unexpected keyword argument 'kw'
  </code></pre>
  
  <p>For the moment I'm getting around it with the following:</p>
  
  <pre><code>&gt;&gt;&gt; exec 'result = f(%s=val)' % kw
  &gt;&gt;&gt; result
  'a was True'
  </code></pre>
  
  <p>but it seems quite clumsy...</p>
  
  <p>(Either python 2.7+ or 3.2+ solutions are ok)</p>