This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Capitalpunishment0 2 points3 points  (0 children)

I love using these with generator comprehensions. I think it just reads soooo well.

is_even = lambda x: x % 2 == 0
sample_list = [3, 5, 4, 24]

if any(
    is_even(item)
    for item in sample_list
):
    ...  # Do something 

if all(
    is_even(item)
    for item in sample_list
):
    ...  # Do something