简体   繁体   English

字典语法错误“无法分配给函数调用”

[英]Dictionary syntax error "can't assign to function call"

I'm trying to find the maximum value of "CrudeRate" and its associated "State_name" using the following code:我正在尝试使用以下代码找到“CrudeRate”的最大值及其关联的“State_name”:

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?我该如何解决?

分配 dict 值时,您需要使用括号而不是括号。

out_dict[C] = max(lst)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM