How do I ensure the script recognizes field values that have already been “used” in a previous row (not necessarily the one just above it)? Below is my source table – the result of a spatial join between two feature classes (equivalent to a land parcel). I have multiple “allocation claim numbers” (AllocClmNum, 1st field) with their respective “recipient credit values” (RecClmNum, 2nd field) associated to one “recipient claim number (RecClmNum, 3rd field) and its credit value (RecCredValReal, 4th field). The script I have subtracts funds from the allocation credit value ( AllocCreVal) stored in a dictionary (thank you Richard Fairehurst) from each RecCreClmNum so that the RecCredValReal value becomes zero, and does so until the AllocCreVal reaches a value at or above 15000. The result is stored in a new table (second one below). In this way the script uses result of the previous the AllocCreVal subtraction and applies it to the next row. The output is shown in the second table : the RecClmNum values to which the script was applied are in the field RecipientClaims. This part works fine (see second table).

The problem is that the script runs regardless of whether the RecClmNum has already been allocated or not
. What I can’t solve is how to NOT include those RecClmNum rows that have already had an allocation applied to them (those highlighted in the green squares). There are about 10000 of these records to go through.
The values in green below should not have been calculated since they were already done using the previous AllocClmNum values.

<SPAN class="comment token"># set your variables for the Allocation Claims feature class</SPAN>
updateFC_AllocClms <SPAN class="operator token">=</SPAN> <SPAN class="string token">"SortedAllocationClaims"</SPAN>
fields_AllocClms <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"AllocClmNum"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"CorrAllocCreVal"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"RecipientClaims"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># set your variables for the feature class with the joined Allocation Claims and Recipient Claims (spatial)</SPAN>
sourceFC_AllocClmsSpj <SPAN class="operator token">=</SPAN> <SPAN class="string token">"AllocationClaimsSPJ"</SPAN>
fields_AllocClmsSpj <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"OBJECTID"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"AllocClmNum"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"RecClmNum"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"RecCreVal"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"AllocStatus"</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># set the dictionary variables</SPAN>
Dict_AllocClmsSpj <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token"># alternative dictionary with "false" values</SPAN>
<SPAN class="comment token"># source: Richard Fairhurst</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>sourceFC_AllocClmsSpj<SPAN class="punctuation token">,</SPAN>fields_AllocClmsSpj<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> searchRows<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> searchRow <SPAN class="keyword token">in</SPAN> searchRows<SPAN class="punctuation token">:</SPAN>
keyValue <SPAN class="operator token">=</SPAN> searchRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> keyValue <SPAN class="keyword token">in</SPAN> Dict_AllocClmsSpj<SPAN class="punctuation token">:</SPAN>
lstRow <SPAN class="operator token">=</SPAN> list<SPAN class="punctuation token">(</SPAN>searchRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
lstRow<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># assign a new keyValue entry to the dictionary storing a list </SPAN>
Dict_AllocClmsSpj<SPAN class="punctuation token">[</SPAN>keyValue<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>lstRow<SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
lstRow <SPAN class="operator token">=</SPAN> list<SPAN class="punctuation token">(</SPAN>searchRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
lstRow<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># dictionary keyValue exists so append to the list</SPAN>
Dict_AllocClmsSpj<SPAN class="punctuation token">[</SPAN>keyValue<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>lstRow<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># run the script</SPAN>
<SPAN class="comment token"># update the Sorted Allocation Claims FC with the new values for Allocation Credits ("CorrAllocCreVal") </SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>updateFC_AllocClms<SPAN class="punctuation token">,</SPAN> fields_AllocClms<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> upRows<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> upRow <SPAN class="keyword token">in</SPAN> upRows<SPAN class="punctuation token">:</SPAN>
x <SPAN class="operator token">=</SPAN> upRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN>
comma <SPAN class="operator token">=</SPAN> <SPAN class="string token">","</SPAN>
KeyAllocationClaim <SPAN class="operator token">=</SPAN> upRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># key value is AllocClmNum</SPAN>
<SPAN class="comment token"># KeyRecipientClaims = upRow[2] # value represents the recipient claim numbers</SPAN>
<SPAN class="keyword token">if</SPAN> KeyAllocationClaim <SPAN class="keyword token">in</SPAN> Dict_AllocClmsSpj<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># if the KeyAllocationClaim is in the dictionary</SPAN>
<SPAN class="keyword token">for</SPAN> record <SPAN class="keyword token">in</SPAN> Dict_AllocClmsSpj<SPAN class="punctuation token">[</SPAN>KeyAllocationClaim<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># something like: if record[1] not in upRow[2]</SPAN>
<SPAN class="comment token"># return the list of values in the field "RecipientCLaims" (upRow[2]).</SPAN>
<SPAN class="comment token"># if record[1] (RecClmNum from </SPAN>
<SPAN class="keyword token">if</SPAN> record<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>upRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">-</SPAN> record<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">>=</SPAN> <SPAN class="number token">15000</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># and as long as credit value is >= to 15000</SPAN>
upRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> upRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">-</SPAN> record<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># subtract the Allocation Credit Value from the Recipient Credit Value in the Dict_AllocClmsSpj</SPAN>
<SPAN class="comment token"># append all the recipient claim numbers "record[1]" to the field "RecipientClaims" in the "SortedAllocationClaims" table separated by a comma </SPAN>
upRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> upRow<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> record<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> comma
record<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
upRows<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>upRow<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>