I have a shapefile where I have polylines and their fields are:
- length
- area into which they fall in
Now I need 3 longest lines from each area. I have 3 areas and 50 polylines, so I should get 3*3=9 records as a result. What I try to do is:
import arcpy
myFile = somePath
sql = ('TOP 3', 'ORDER BY "length" DESC GROUP BY "area_id" ')
cursor = arcpy.da.SearchCursor(myFile , "*", None, None, False, sql)
with cursor:
for r in cursor:
print r
I get all of 50 records here. The same happens when I set `sql` to just `('TOP 1', None) or anything else.
Is the syntax wrong here?
Solved! Go to Solution.
I get 'IndexError: list assignment index out of range' on this line:
selections[row[0]][row[1]] = row[2]
Since selections is defaultdict(dict), I think the error can appear only because there is no row[0], row[1] or row[2]. Please try to print it and see it you get correct results from cursor.