title: Handling lists and dicts identically - with default
body: <p>I have a function which should work with both <code>list</code>s and <code>dict</code>s:</p>
  
  <pre><code>def row2tuple (row, md):
      return (row[md.first], row[md.next])
  </code></pre>
  
  <p>and if <code>row</code> is a <code>list</code> then <code>md.first</code> and <code>md.next</code> will be <code>int</code>s, and if <code>row</code> is a <code>dict</code>, they will be <code>str</code>ings.</p>
  
  <p>However, this results in an error if <code>row</code> is a <code>dict</code> and the fields are missing. If I use the <code>get</code> method:</p>
  
  <pre><code>def row2tuple (row, md):
      return (row.get(md.first), row.get(md.next))
  </code></pre>
  
  <p>it does precisely what I want for <code>dict</code>s but it does not work at all for <code>list</code>s.</p>
  
  <p>I could do, of course</p>
  
  <pre><code>def row2tuple (row, md):
      if isinstance(row,list):
          return (row[md.first], row[md.next])
      return (row.get(md.first), row.get(md.next))
  </code></pre>
  
  <p>but it looks ugly.</p>
  
  <p>Is there a more pythonic/concise way to do that?</p>