簡體   English   中英

Python max arg 是非空列表上的空序列

[英]Python max arg is empty sequence on non empty list

我從這行代碼中得到ValueError: max() arg is an empty sequence

result = {}

ids = [...] # may be empty
objects_from_ids = func_to_fetch_objects(delivery_ids) # returns empty list, if ids are empty, or list of objects, with corresponding ids

if objects_from_ids:
   result["max_dt"] = max(d["dt"] for d in objects_from_ids) # Here comes error

誰能解釋一下,為什么會發生這種情況? 我已經閱讀了有關空序列案例的默認值的答案,但想了解這種情況

objects_from_ids可能是空對象列表或錯誤在func_to_fetch_objects()

嘗試在 if 子句中打印值以了解里面發生了什么。

暫無
暫無

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

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