
# filter does the work of a list-comprehension with an if construct:

def is_even(x):
    """True if x is even, False if x is odd"""
    return x % 2 == 0


xs = [1, 2, 3, 4]

# List comprehension with IF clause:

x_evens = [x for x in xs if is_even(x)] 		# [2, 4]
print(x_evens)

# Same result with filter()

x_evens = filter( is_even, xs )
print(list(x_evens))


# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# We can use functools.partial to create a function that doubles an input list
# like this:
# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

import functools

list_evener = functools.partial( filter, is_even) # list_evener(x) ~= filter(is_even, x)

x_evens = list_evener(xs)
print(list(x_evens))



