Python provides map and filter functions to process computations on the list of items. Here is a list of examples how to use map and filter.
Compute the square of 1 to 10
def f(x): return x*x map(f, range(1, 11))
map(lambda x: x*x, range(10))
Python filter function examples
Extract the event numbers from 1 to 10
def f(x): return x%2 == 0 filter(f, range(1, 11))
or use lambda functions
filter(lambda x: x%2 == 0, range(1, 11))
0 comments:
Post a Comment