title: Reduce tuple of one item (singleton) to its value
body: <p>Is there a built-in way to reduce a <a href="http://python-reference.readthedocs.io/en/latest/docs/tuple/#tuple" rel="nofollow noreferrer">singleton tuple</a> to its (only) value?</p>
  
  <p>I can achieve this using a function like:</p>
  
  <pre><code>def foo(tup):
      if len(tup) == 1:
          return tup[0]
      return tup
  </code></pre>
  
  <p>This reduces a singleton to its value and leaves a non-singleton tuple as is:</p>
  
  <pre><code>&gt;&gt;&gt; x = (3, )
  &gt;&gt;&gt; foo(x)
  3
  &gt;&gt;&gt; x = (3, 4)
  &gt;&gt;&gt; foo(x)
  (3, 4)
  </code></pre>
  
  <p>But this seems like a fairly low-level task and I bet it's already lurking somewhere in the Python standard library. The functionality kind of reminds me of <a href="https://stackoverflow.com/questions/34990652/why-do-we-need-np-squeeze"><code>numpy.squeeze</code></a> but that leaves us with an <code>array</code> which may not be what we want.</p>