Python: Python Functional Programming

python in functional programming support:

The filter function corresponds to the function of the filter. Bool_func a Boolean function call to iterate through each element in seq; bool_seq so returns a value of true return sequence elements.

a = [1,2,3,4,5,6,7]
b = filter(lambda x: x > 5, a)
print b
[6,7]

function map each item is a sequence of function sequentially executed, the following is a sequence for each item multiplied by 2:

a = map(lambda x:x*2,[1,2,3])
list(a)
[2, 4, 6]

Iterative reduce function call is a function of each sequence item, following a factorial 3:

reduce(lambda x,y:x*y,range(1,4))
6

Guess you like

Origin blog.csdn.net/weixin_44523387/article/details/91896896