Python all lambda is not needed because simple list comprehension can do the same work. In this tutorial, we tried to use all() function with lambda.
Python all lambda example
Simple example code.
good_foods = ['apple', 'carrot']
junk_foods = ['soda', 'burger']
my_foods = ['banana', 'carrot', 'bread', 'apple', 'soda']
res = all(map(lambda x: x in my_foods, good_foods))
print("all good_foods in my_food:", res)
res = all(map(lambda x: x in my_foods, good_foods))
print("all junk_foods in my_food:", res)
Output:
Comment if you have any doubts or suggestions on this Python all() function topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.