In contrast with
takewhile which stops the first time it encounters a non-matching value,
filter continues past non-matching values and produces a list containing all of the values that satisfy the predicate.
Here we use
filter in Python to select, from among the natural numbers, only those that are even:
>>> it = filter(lambda x: x % 2 == 0, count(1)) >>> list(islice(it, 10)) 2, 4, 6, 8, 10, 12, 14, 16, 18, 20][