Don't forget to also checkout my second blog containing articles to all other related ICT topics!!

Thursday, May 3, 2012

Itertools ifilter method explained

Itertools ifilter makes an iterator that filters elements from iterable returning only those for which the predicate is True. If predicate is None, return the items that are true.
from itertools import ifilter

numbers = [0,1,3,5,6,8,9,13]

for even_number in ifilter(lambda number: number %2 == 0, numbers):
    print even_number

0
6
8

No comments:

Post a Comment