I am referring to the following python code
all(a==2 for a in my_list)
I expect the above code to return True if all the elements in my_li
It's true because for every element in the list, all 0 of them, they all are equal to 2.
You can think of all being implemented as:
def all(list, condition):
for a in list:
if not condition(a):
return false
return true
Whereas any is:
def any(list, condition):
for a in list:
if condition(a):
return true
return false
That is to say, all is innocent until proven guilty, and any is guilty until proven innocent.