0

From the python docs:

all()

Return True if all elements of the iterable are true (or if the iterable is empty).

any()

Return True if any element of the iterable is true. If the iterable is empty, return False.

What's the logic behind making all([]) True? I would think (perhaps naively) that if you had an empty set or list or whatever, doing all() on it should evaluate to False, since none of the items are True.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
David542
  • 104,438
  • 178
  • 489
  • 842
  • 2
    "since none of the items are True". But none of them are false either :) – Loocid Oct 14 '19 at 00:19
  • It has been discussed here: https://stackoverflow.com/questions/11979683/why-python-built-in-all-function-returns-true-for-empty-iterables any([]) can be explained in similar fashion based on that. – san Oct 14 '19 at 00:19
  • 1
    Saying "every item is true" is equivalent to saying "there are no items that are not true". That applies to `[]` – khelwood Oct 14 '19 at 00:20
  • `any` starts `False`, and iterates until it hits a `True`, then quits. `all` starts `True` and iterates until it hits a `False`, then quits. You can confirm this by `timeit` one lists of various lengths. – hpaulj Oct 14 '19 at 01:24

0 Answers0