Printing the Map,filter function directly in Python2 will output the result directly. However, in the Python3 to make some changes, the output need to use the list () for display conversion, and the reduce function is placed in the Functools package, the following code
From functools import reduce
import math
def format_name (s): Return
S.upper ()
def is_odd (x):
return x 2 = 1
def sqr_integer (x):
r = Math.floor (math.sqrt (x)) return
x = = R*r
def f (x, y):
return x + y
map puts function f on each element of the list, gets a iterator and returns.
Print (Map (format_name, [' Adam ', ' LISA ', ' BarT ']))
# Reduce () incoming function f must receive two parameters, reduce () Call function f repeatedly on each element of the list and return the final result value. Reduce () can also receive the 3rd optional parameter as the initial value of the calculation.
print (Reduce (f, [1, 3, 5, 7, 9], M))
# Filter () automatically filters out elements that do not meet the criteria according to the results of the judgment, and returns the iterator that are composed of the eligible elements.
Print (Filter (is_odd, [1, 4, 6, 7, 9,,))
Print (List filter (Sqr_integer,range (100)))
The results of the operation are as follows
[' ADAM ', ' LISA ', ' BART ']
"[
1, 7, 9,"]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]