Cool cursor dictionary constructor one-liner

Discussion created by csny490 on Mar 8, 2012
Latest reply on Nov 4, 2013 by doug.sands
I bet someone else will think this is cool too.

In one line, turn your attribute table into a Python dictionary. Of course faster (and actually one line not 3) if you don't have to use .getValue!

Apparently there is a bit more memory overhead doing it this way, but hey...

keyField = "OBJECTID"
valueField = "DIFFERENT_ID"
exampleDict = dict([(searchRow.getValue(keyField), searchRow.getValue(valueField)) for searchRow in arcpy.SearchCursor(myTable)])