Skip to main content
added 14 characters in body
Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 188

Use collections.defaultdict(list) to store your data:

import arcpy, collections

fc = r'C:\data.gdb\somefeatureclass' #Or shapefile
fields = ['Road_Name','X','Y']

d = collections.defaultdict(list)

with arcpy.da.SearchCursor(fc,fields) as cursor:
    for roadname,x,y in cursor:
        d[roadname].append([x,y])

Key will be roadname and values will be a list of lists of coordinate pairs. For example if you do:

d['Washington street']

you will get:

[[1,2],[1,4],...]

and the 21 remaining coordinate pairs.

Your next step will perhaps be to iterate over keys and values, see this question: Iterating over key and value of defaultdict dictionaries

Use collections.defaultdict(list) to store your data:

import arcpy, collections

fc = r'C:\data.gdb\somefeatureclass'
fields = ['Road_Name','X','Y']

d = collections.defaultdict(list)

with arcpy.da.SearchCursor(fc,fields) as cursor:
    for roadname,x,y in cursor:
        d[roadname].append([x,y])

Key will be roadname and values will be a list of lists of coordinate pairs. For example if you do:

d['Washington street']

you will get:

[[1,2],[1,4],...]

and the 21 remaining coordinate pairs.

Your next step will perhaps be to iterate over keys and values, see this question: Iterating over key and value of defaultdict dictionaries

Use collections.defaultdict(list) to store your data:

import arcpy, collections

fc = r'C:\data.gdb\somefeatureclass' #Or shapefile
fields = ['Road_Name','X','Y']

d = collections.defaultdict(list)

with arcpy.da.SearchCursor(fc,fields) as cursor:
    for roadname,x,y in cursor:
        d[roadname].append([x,y])

Key will be roadname and values will be a list of lists of coordinate pairs. For example if you do:

d['Washington street']

you will get:

[[1,2],[1,4],...]

and the 21 remaining coordinate pairs.

Your next step will perhaps be to iterate over keys and values, see this question: Iterating over key and value of defaultdict dictionaries

Source Link
Bera
  • 77.8k
  • 14
  • 78
  • 188

Use collections.defaultdict(list) to store your data:

import arcpy, collections

fc = r'C:\data.gdb\somefeatureclass'
fields = ['Road_Name','X','Y']

d = collections.defaultdict(list)

with arcpy.da.SearchCursor(fc,fields) as cursor:
    for roadname,x,y in cursor:
        d[roadname].append([x,y])

Key will be roadname and values will be a list of lists of coordinate pairs. For example if you do:

d['Washington street']

you will get:

[[1,2],[1,4],...]

and the 21 remaining coordinate pairs.

Your next step will perhaps be to iterate over keys and values, see this question: Iterating over key and value of defaultdict dictionaries