from functools importreducedefadd(x,y):return x+y
res =reduce(add,[1,2,3,4,5])
res =reduce(lambda x,y:x+y,[1,2,3,4,5])print(res)
# ex: 统计sentences = ['The Deep Learning textbook is a resource intended to help students and practitioners enter the field of machine learning in general and deep learning in particular.']中‘learning’出现的次数。
sentences =['The Deep Learning textbook is a resource intended to help students and practitioners enter the field of machine learning in general and deep learning in particular.']from functools importreduce
word_count =reduce(lambda a,x:a+x.count("learning"),sentences,0)print(word_count)