4 ms·
Not only is it not idiomatic; it's functionally incorrect. An iterable containing `[]`, `None`, or any other value that is false in a boolean context would ret
by hxtk 9y ago
Not only is it not idiomatic; it's functionally incorrect.
An iterable containing `[]`, `None`, or any other value that is false in a boolean context would return true. They've assumed that `(0 -> false) -> (false -> 0)`, which is simply not true.
Even if you're dealing with a context that cannot pass in an iterable with non-zero "falsy" values then it needs to be explicitly documented. At that point, why not "document" it by being explicit with the code. This is how I'd do it, but I feel like it could be made cleaner:
def contains_zero(iterable):
return any([i is 0 for i in iterable])
Edit: I forgot how to python. It's `return 0 in iterable`.
- deleted 9y ago[deleted]