+ 2
What all(code) do in Python?
What this code do? if all(filter(lambda x: x%4==0, num_list)): print('yes') my question is, what all() do here? note that num_list here is a generic list entered by user.
2 Answers
+ 2
all() is a method that returns True when all elements in the given iterable are true. If not, it returns False.
Reference: programiz
Hope this helps!!!
0
all() function returns true if all elements in the list are true. Basically it's unnecessary because your filter function will return a list that contains only true values.
def all(list):
for element in list:
if not element:
return False
return True