map
num_l = [1,6,8,9] def map_test(func,array): ret = [] for i in array: res = func(i) ret.append (res) return ret def jia(x): return x+1 # Built-in function Print (map_test ( the lambda X: X +. 1 , num_l)) print (map_test (Jia, num_l)) # Only one iteration # RES = the Map (the lambda the X-: the X-+ 1, num_l) # for i in RES: # Print (i) # Print (List (RES))
filter
#filter函数 movie_people=['alex_sb','wupeiqi_sb','linhaifeng','yuanhao_sb'] print(filter(lambda n:not n.endswith('sb'),movie_people)) res=filter(lambda n:not n.endswith('sb'),movie_people) print(list(res)) print(list(filter(lambda n:not n.endswith('sb'),movie_people)))
reduce
# def reduce_test(func,array): # res=array.pop(0) # for num in array: # res=func(res,num) # return res # # print(reduce_test(lambda x,y:x*y,num_l)) num_l=[1,2,3,100] def reduce_test(func,array,init=None): if init is None: res=array.pop(0) else: res=init for num in array: a = func (business, whether) return it print(reduce_test(lambda x,y:x*y,num_l,100))