NeilOllerhead

Comparing two consecutive rows in a featureclass in a python script.

Discussion created by NeilOllerhead on Feb 28, 2011
Latest reply on Feb 28, 2011 by lpugh01
I would like to know how I can compare data in two consecutive rows in a feature class.  I want to compare data in two consecutive rows and based on this comparison decide if I want to delete the first row in the pair. See example below.


table
-------------
          id    col_a    col_b    col_c
row-1   1      dog      red      sad
row-2   2      dog      red    happy
row-3   3      cat     black     mad


logic
-------------
a = get_first
b = get_next

for each row in table:
    if a.col_a = b.col_a:
        delete a
    a = b
    b = get_next

If I use a cursor where I say a = cur.next() and b=cur.next() they both end up pointing to the second object fetched from the cursor.  I can't seem to figure out how to peek into the next row in a table without advancing the cursor pointer.  In Oracle there are Lead / Lag functions that let you look at the next / previous rows in a table.  Any advice would be greatly appreciated.  Thanks in advance.

Neil

Outcomes