Filter

Now consider another common pattern: going through a list and keeping only those items that meet certain criteria. This is called a filter.

Again, this pattern of computation is so common that python offers a more compact and general way to do it, the filter function. filter takes two arguments, a function and a sequence. The function takes one item and return True if the item should. It is automatically called for each item in the sequence. You don’t have to initialize an accumulator or iterate with a for loop.

Exercises

Next Section - List Comprehensions