or better yet...
exampleDict = dict([(r.KEY, (r.VALUE1, r.VALUE2)) for r in arcpy.SearchCursor(myTbl)])
I've always liked this little piece of code, but a couple of things have always bothered me. The dictionary that results gives you the attributes of your 'KEY' as a series of values (r.VALUE1, r.VALUE2), but you lose the attribute name. Working with big datasets with many 'VALUE's could be difficult. Also, it requires that you go in and enter each field name you wanted included in the output dictionary. Again, with big datasets this may be problem.This little ditty uses nested list comprehension to solve those problems:# for this example, use the Census 2000 state shapefile
myShp = 'R:\\data\\Census\\2000\\Shape\\ST.shp'
myDict = dict([((r.ST_ABBREV, f.name), r.getValue(f.name)) for f in ap.ListFields(myShp) for r in ap.SearchCursor(myShp)])
>>> myDict[('WY', 'STATE_NAME')]
>>> 'Wyoming'
>>> myDict[('MD', 'ID')]
>>> '24' #this is the FIPS code for Maryland
Even though calling this a 'one-liner' is a bit of stretch (it's 123 characters), this lets me access the entire shapefile attribute table, in this case, as a dictionary using a two-item tuple as the key.And, I don't need to know the names or number of fields in advance. All I have to do is provide the name of the field I want to serve as the key, which is ST_ABBREV in this case.