5

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:

SyntaxError: Can't assign to function call

What is the problem with the code? How can I fix it?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
David Meek
  • 193
  • 1
  • 3
  • 8

1 Answers1

9

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

out_dict[C] = max(lst)
aneroid
  • 12,983
  • 3
  • 36
  • 66
garnertb
  • 9,454
  • 36
  • 38