Python: Filter List

By Xah Lee. Date: .

Filter List

filter(f, list)
Return a new iterator, such that f(item) returns True.
# return True if divisible by 2
def ff(n):
    return n % 2 == 0

aa = [0, 1, 2, 3, 4, 5]

bb = filter(ff, aa)

print(list(bb) == [0, 2, 4])

Python, Data Structure