簡體   English   中英

字典語法錯誤“無法分配給函數調用”

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

我正在嘗試使用以下代碼找到“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)

但是當我運行它時,我得到:

SyntaxError: Can't assign to function call

代碼有什么問題? 我該如何解決?

分配 dict 值時,您需要使用括號而不是括號。

out_dict[C] = max(lst)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM