> all([])
True
> any([])
False
Not very consistent philosophy in that case. Surely if 'all' is True then 'any' got to be too? > all([])
True
> any([])
False
Not very consistent philosophy in that case. Surely if 'all' is True then 'any' got to be too?Some examples are "if something is true for 'all students', it should be true for any group of students", and if "all students have a hat" is true, then it should not be true that "any student had no hat", etc.
No. `any([])` means "some element of [] is true", which is false because there aren't any elements. `all([])` means "all elements of [] are true", which is true because it's (classically, anyway) got to be true or false, and being false would require that there be some element of [] that isn't true, which there isn't.
More generally, `!all([!x for x in xs])` (or whatever the syntax is; I'm not a Python programmer)—meaning "it's not the case that the negation of every element of xs is true"—is `any(xs)`, so `!all([])` is `any([])`.
Any would be more formally: there is an element of the list which is true. But the list doesn't have any elements, so that's false.
Looks logical to me. Plus you get that `not any( map(lambda x: not x, l) )` is the same as `all(l)` for any list `l`.
It is just a matter of convention and I see no logic behind why any convention would be worse or wrong. But I believe if 'any' implies 'at least one' so should 'all' otherwise they use different conventions.
In practice I get it was arbitrary choices and this is just how you end up when doing the obvious implementation.
def all(l):
for e in l:
if not e:
return False
return True
def any(l):
for e in l:
if e:
return True
return FalseThe conventions they use are not an arbitrary choice, and are those of predicate logic. any() is the “for any” (existential quantification) operator, while all() is the “for all” (universal quantification) operator.
They are deeply connected: “all items in xs are true” is “there are not any items in xs that are not true”, or, in code terms, all(xs) == not any(not x for x in xs).
And, vice versa, any(xs) == not all(not x for x in xs)
You're logging incoming web requests and then gathering statistics in 5 minute intervals.
During one interval, you get no requests.
You check to see...did "all" of the requests get processed without errors? The answer is Yes, because to say No would imply there were errors.
Did "any" of the requests cause an error? The answer is No, because to say Yes would imply at least one error.
any (<5) [6,7,8]
any (<5) ([6,7,8] ++ [])
(any (<5) [6,7,8]) || (any (<5) [])
False || True
TrueIn order to satisfy “does any x satisfy y” you need find an example that does.