Solved! Go to Solution.
import arcpy # Change these 2 input parameters accordingly... fc = r'E:\schoolTestData\test.gdb\schoolJoinToPolys' outField = 'outGrades' delField = arcpy.AddFieldDelimiters(fc, outField) # This query works whether shapefile or gdb fc. query = delField + ' IS NOT NULL AND ' + delField + ' NOT IN (\' \')' rows = arcpy.UpdateCursor(fc, query) for row in rows: # This populates a list, row by row... # outGradesRaw will potentially contain 'P' vals. # outGrades is a new list with 'P' vals eliminated. outGradesRaw = row.getValue(outField).split(',') outGrades = [] for each in outGradesRaw: if not each[0:1] == 'P': outGrades.append(each) # sorted outGrades for loop, comparison of successive items outGrades.sort() # initializing count count = 0 compareVal = outGrades[0] # Loop over the sorted list to count. for each in outGrades: if each == compareVal: count += 1 else: # This conditionally sets the fieldName to load... if not compareVal[0:1] == 'K': fieldName = 'Grade_' + str(int(compareVal)) else: fieldName = 'Grade_K' # Successive K vals may not match, # so will be temp stored in att table, # then fetched to make a cumulative count. count += row.getValue(fieldName) # count committed to row obj from att table row.setValue(fieldName, count) # row obj committed to cursor obj of att table rows.updateRow(row) # resetting count to 1 count = 1 # setting compareVal to current val compareVal = each # load the count for the last val, identical to part of above block if not compareVal[0:1] == 'K': fieldName = 'Grade_' + str(int(compareVal)) else: fieldName = 'Grade_K' count += row.getValue(fieldName) row.setValue(fieldName, count) rows.updateRow(row) del rows