title: How do you programmatically pass in keywords to function in python?
body: <p>I have some code I'm trying to refactor, which looks a bit like this in python 3:</p>
  
  <pre><code>  # some_obj.query(streetaddress="burdon")
    # some_obj.query(area="bungo")
    # some_obj.query(region="bingo")
    # some_obj.query(some_other_key="bango")
  </code></pre>
  
  <p>How I can DRY this up so I have something like this? </p>
  
  <pre><code># define a list of tuples like so:
  set_o_tuples = [
    ("streetaddress", "burdon")
    ("area", "bungo"),
    ("region", "bingo"),
    ("some_other_key", "bango"),
  ])
  </code></pre>
  
  <p>And then call it in a function </p>
  
  <pre><code>for key, val in set_o_tuples:      
    some_obj.query(key=val)
  </code></pre>
  
  <p>When I try to run this code, I get an exception like the following - as Python doesn't like keywords being passed in like this:</p>
  
  <pre><code>SyntaxError: keyword can't be an expression
  </code></pre>
  
  <p>What <em>is</em> the idiomatic way to DRY this up, so I don't have to repeat loads of code like the example above?</p>
  
  <p>Update: sorry folks, I think the example I put together above missed a few important details. I basically have some pytest code like so</p>
  
  <pre><code>def test_can_search_by_location(self, db, docs_from_csv):
      """
      We want to be able to query the contents of all the below fields when we query by location:
      [ streetaddress, locality, region, postcode]
      """
  
      search = SomeDocument.search()
  
      locality_query = search.query('match', locality="some val")
      locality_res = locality_query.execute()
  
      region_query = search.query('match', region="region val")
      region_query_res = region_query.execute()
  
      postcode_query = search.query('match', postcode="postcode_val")
      postcode_query_res = postcode_query.execute()
  
      streetaddress_query = search.query('match', concat_field="burdon")
      field_query_res = field_query.execute()
  
      location_query = search.query('match', location=concat_value)
      location_query_res = location_query.execute()
  
      assert len(locality_query_res) == len(location_query_res)
      assert len(region_query_res) == len(location_query_res)
      assert len(streetaddress_query_res) == len(location_query_res)
      assert len(postcode_query_res) == len(location_query_res)
  </code></pre>
  
  <p>I was trying to DRY up some of this, as there are similar examples I have, but after reading the comments, I've rethought it - the savings in space don't really justify the changes. Thanks for the pointers.</p>