Check if values in list exceed threshold a certain amount of times and return index of first exceedance
<p>I am searching for a clean and pythonic way of checking if the contents of a list are greater than a given number (first threshold) for a certain number of times (second threshold). If both statements are true, I want to return the index of the first value which exceeds the given threshold.</p>

<p><strong>Example</strong>:</p>

<pre><code># Set first and second threshold
thr1 = 4
thr2 = 5

# Example 1: Both thresholds exceeded, looking for index (3)
list1 = [1, 1, 1, 5, 1, 6, 7, 3, 6, 8]

# Example 2: Only threshold 1 is exceeded, no index return needed
list2 = [1, 1, 6, 1, 1, 1, 2, 1, 1, 1]
</code></pre>

<p>I don't know if I'd call it clean or pythonic, but this should work</p>

<pre><code>def get_index(list1, thr1, thr2):
    cnt = 0
    first_element = 0
    for i in list1:
        if i &gt; thr1:
            cnt += 1
            if first_element == 0:
                first_element = i

    if cnt &gt; thr2:
        return list1.index(first_element)
    else:
        return "criteria not met"
</code></pre>

python list iterator threshold