Next: Reduce. Up: MapReduce and Previous: Map.

Filter.

filter(function, sequence) returns a sequence (of the same type, if possible) consisting of those items from the sequence for which function(item) is true. For example, to compute some primes:


        >>> filter(lambda x: x%2 != 0 and x%3 != 0, range(2, 25))
        [5, 7, 11, 13, 17, 19, 23]
        >>>


guido@cwi.nl