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>You're saving the old value too soon</p>

<pre><code>    old = i % 10
    if (old == 1) and (i % 10 == 1): 
        count1_1 += 1 
</code></pre>

<p>should be</p>

<pre><code>        if (old == 1) and (i % 10 == 1): 
            count1_1 += 1 
        old = i % 10
</code></pre>

<p>or <code>old</code> and <code>i % 10</code> are identical: not what you want (since both expressions of your <code>if</code> test the same thing)</p>

python