Functional Programming Tools: filter : Functional Programming « Function « Python






Functional Programming Tools: filter

Functional Programming Tools: filter
# "filter(function, sequence)" returns a sequence consisting of those items from 
# the sequence for which function(item) is true. If sequence is a string or tuple, 
# the result will be of the same type; otherwise, it is always a list. 
# For example, to compute some primes:

def f(x): return x % 2 != 0 and x % 3 != 0

print filter(f, range(2, 25))

           
       








Related examples in the same category

1.Functional Programming Tools: mapFunctional Programming Tools: map
2.Functional Programming Tools: map: More than one sequence may be passedFunctional Programming Tools: map: More than one sequence may be passed
3.Functional Programming Tools: reduceFunctional Programming Tools: reduce
4.Functional Programming Tools: reduce 2Functional Programming Tools: reduce 2