我在 python 中使用过 min(A,B,C,D)。这在查找最低值方面非常有效,但是,如果我在任何变量 A、B、C 或 D 中有空值(0 值),它将返回空值(或 0)。在我的案例中如何返回非空值或非零值有什么想法吗?谢谢
最佳答案
我会使用一个过滤器来处理 None、0、False 等...
>>> min(filter(None, [1, 2, 0, None, 5, False]))
1
来自docs :
Note that filter(function, iterable) is equivalent to [item for item in iterable if function(item)] if function is not None and [item for item in iterable if item] if function is None
关于python - 使用python查找不为空的最低值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21084714/