Storing the value that meets a requirement in variable and finding the next value that also meets that requirement
<p>I am trying to write a code that iterates through a list and if i % 10 equals 1, then I store that <code>i</code> in a variable. Then, I want my code to keep iterating through the list and if another i value meets the same requirement than it adds to a count. </p>

<p>This is what I have right now but it is just saving an i value and than adding to a count. This is because what I want to be my next i value is just the first i value that meets my requirement.</p>

<pre><code>count 1_1 = 0
for i in B:
    if some_reqirement:
        if some_other_reqirement:
            if (old == 1) and (i % 10 == 1): 
                count1_1 += 1
            old = i % 10 
</code></pre>

<p>Does anyone know how I could fix this?</p>

<p>EDIT:</p>

<p>this is the code with requirement, and I have tested the rest of the code and it works how i want it to.</p>

<p>A is a range with certain values replaced with with the value 1 and b is just a range.</p>

<pre><code>count1_1 = 0    
for i in B:
    if B[i] % 10 == 1 and B[i + 2] % 10 == 3:
        if A[i] * A[i + 2] == 1:
            if (old == 1) and (i % 10 == 1): 
                count1_1 += 1
            old = i % 10 
</code></pre>

<p>I still see <code>old</code> as essentially a boolean flag so let's make it one (called <code>previous_1</code>), but this time, instead of only being triggered True once, we'll change it's value based on every <code>i</code> that passes both requirements:</p>

<pre><code>count1_1 = 0

previous_1 = False

for i in B:
    if B[i] % 10 == 1 and B[i + 2] % 10 == 3:
        if some_other_reqirement:
            current_1 = i % 10 == 1
            if current_1 and previous_1:
                    count1_1 += 1
            previous_1 = current_1
</code></pre>

python