title: Python: return the index of the first element of a list which makes a passed function true
body: <p>The <code>list.index(x)</code> function returns the index in the list of the first item whose value is <code>x</code>.</p>
  
  <p>Is there a function, <code>list_func_index()</code>, similar to the <code>index()</code> function that has a function, <code>f()</code>, as a parameter. The function, <code>f()</code> is run on every element, <code>e</code>, of the list until  <code>f(e)</code> returns <code>True</code>. Then <code>list_func_index()</code> returns the index of <code>e</code>.</p>
  
  <p>Codewise:</p>
  
  <pre><code>&gt;&gt;&gt; def list_func_index(lst, func):
        for i in range(len(lst)):
          if func(lst[i]):
            return i
        raise ValueError('no element making func True')
  
  &gt;&gt;&gt; l = [8,10,4,5,7]
  &gt;&gt;&gt; def is_odd(x): return x % 2 != 0
  &gt;&gt;&gt; list_func_index(l,is_odd)
  3
  </code></pre>
  
  <p>Is there a more elegant solution? (and a better name for the function)</p>