AnsweredAssumed Answered

SearchCursor, create unique lists, convert to dictionary

Question asked by matthewrusso on Feb 5, 2015
Latest reply on Feb 5, 2015 by blake.terhune
fc = 'Texas'
field1 = "COUNTY_CODE"
field2 = "NAME10" 
list1 = []   
list2 = [] 
rows = arcpy.SearchCursor(fc)

for row in rows:
    list1.append(row.getValue(field1))
    list2.append(row.getValue(field2))
else:
    print "loop failed"

#Get Unique Values from the List         
uSet1 = set(list1)
uSet2 = set(list2)

#Convert the set to a list
uList1 = list(uSet1)
uList2 = list(uSet2)

#Print The list
print uList1
print uList2

#Create Dictionary from the 2 lists and print results
from itertools import chain, repeat
d = dict(zip(uList1, chain(uList2, repeat(None))))

for key,val in d.items():
    print key,val

Outcomes