Python built-in functions

Python filter is very handy python built-in function to filter iterables (e.g. lists) in python. But it returns a list which may consume huge memory when data behind iterable is huge. In such case using itertools.ifilter is a better choice. itertools.ifilter takes a lazy approach and calls the filter function only when needed. Here are quick examples for both approaches.

filter example

Here filter function is called for all values the moment filter is called.