I know it has a good reason, but I want to know what reason?
>>> print all([])
True
If all() is intended to check if every item on iterable evaluates to "True", and we know empty lists are evaluated to False
>>> bool([])
False
So why the all() returns True for empty lists?
< edit >
I already read the docs, and I know the implementation
def all(iterable):
for element in iterable:
if not element:
return False
return True
But the question is why not?
def all(iterable):
if not iterable:
return False
for element in iterable:
if not element:
return False
return True
There is a logic on this? if you have a list of done-tasks
today_todo_status = [task.status for task in my_todo if task.date == today]
can_i_go_home = all(today_todo_status)
Ok, on the above hypothetical example it really makes sense, if I have no tasks, so I can go home.
But there are other cases and I dont think all() was made for todo lists.. LOL
< /edit >