BrokenLegMike

Looping through a Field and grouping data

Discussion created by BrokenLegMike on Oct 7, 2011
Latest reply on Oct 7, 2011 by csny490
Hey folks,

I'm trying to loop through a field in a feature classes and store groups of values in a variable to be used later on. In the example below, I want to loop through each row and when the value changes, I want to store all the groups of values in a variable and copy them to a separate feature class (i.e. Group all the M1's together, group all the M21's together and so on). I don't want to use an if/else statement, because there are a few hundred different values in my field.

Example Field:

    M1
    M1
    M1
    M21
    M21
    M23b
    M23b
    S2
    S23b
    S23B
    O1
    O2
    O2
    O2

In the script below, I used a search cursor to set up for my loop. I also sorted the column ascendingly to make it easier to group the data and detect changes as the loop goes through, but after that, I'm kind hung up on how to make the loop work. I'm convinced this is possible, but the solution is escaping me. Can anyone suggesthow to do this?

import arcpy
from arcpy import env

env.workspace = "Z:\ESRI\TEST.gdb"

cur = arcpy.SearchCursor("POLYGON_FC", "", "", "RIVERS", "RIVERS A")

Outcomes