title: Why is there no first(iterable) built-in function in Python?
body: <p>I'm wondering if there's a reason that there's no <code>first(iterable)</code> in the Python built-in functions, somewhat similar to <code>any(iterable)</code> and <code>all(iterable)</code> (it may be tucked in a stdlib module somewhere, but I don't see it in <code>itertools</code>). <code>first</code> would perform a short-circuit generator evaluation so that unnecessary (and a potentially infinite number of) operations can be avoided; i.e.</p>
  
  <pre><code>def identity(item):
      return item
  
  def first(iterable, predicate=identity):
      for item in iterable:
          if predicate(item):
              return item
      raise ValueError('No satisfactory value found')
  </code></pre>
  
  <p>This way you can express things like:</p>
  
  <pre><code>denominators = (2, 3, 4, 5)
  lcd = first(i for i in itertools.count(1)
      if all(i % denominators == 0 for denominator in denominators))
  </code></pre>
  
  <p>Clearly you can't do <code>list(generator)[0]</code> in that case, since the generator doesn't terminate.</p>
  
  <p>Or if you have a bunch of regexes to match against (useful when they all have the same <code>groupdict</code> interface):</p>
  
  <pre><code>match = first(regex.match(big_text) for regex in regexes)
  </code></pre>
  
  <p>You save a lot of unnecessary processing by avoiding <code>list(generator)[0]</code> and short-circuiting on a positive match.</p>