【问题标题】:Python max arg 是非空列表上的空序列
【发布时间】:2022-01-23 14:23:25
【问题描述】:

我从这行代码中得到 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

谁能解释一下,为什么会发生这种情况? 我已经阅读了有关空序列案例的默认值的答案,但想了解这种情况

【问题讨论】:

    标签: python python-3.x python-2.7


    【解决方案1】:

    objects_from_ids 可能是空对象列表,或者错误在 func_to_fetch_objects()

    尝试在 if 子句中打印值以了解里面发生了什么。

    【讨论】:

    • 我想通了,问题出在哪里,ty for Empty Object 建议。
    猜你喜欢
    • 2014-11-26
    • 2016-07-03
    • 2014-09-27
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多