Arcpy: Dictionary syntax error "can't assign to function call"

David Meek picture David Meek · Apr 10, 2013 · Viewed 20.9k times · Source

I'm trying to find the maximum value of "CrudeRate" and its associated "State_name" using the following code:

import arcpy
arcpy.env.workspace = "C:\\"

shp = r"C:\\USCancer2000.dbf"
rows = arcpy.SearchCursor(shp)
CrudeRate= "CrudeRate"
State_name= "State_name"

out_dict = {}
for row in rows:
    for C in CrudeRate:
        lst = []
        if row.CrudeRate == C:
            lst.append(row.CrudeRate)
        out_dict(C) = max(lst)
del row,rows
for CrudeRate in out_dict:
    print CrudeRate, State_name

but when I run it I get:

Sytnax error: Can't assign function call

Does anyone see the problem and how to work around it?

Answer

garnertb picture garnertb · Apr 10, 2013

You need to use brackets instead of parentesis when assigning a dict value.

out_dict[C] = max(lst)