Python's built-in functions: map , filter , reduce summary

map function:

#Process each element in the sequence, the result is a 'list', the number and position of the list elements are the same as the original

 

filter function:

# Traverse each element in the sequence, judge each element to get a boolean value, if it is true, stay

people=[{'name':'wangyue','age':10},
        {'name':'songyang','age':30}
        ]
rec=filter(lambda p:p['age']>10,people)
print list(rec)

 reduce function:

Process a sequence, then combine the sequence with the operation

from functools import reduce
print (reduce(lambda x,y:x+y,range(100),100))

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324845923&siteId=291194637