python(filter, map, reduce, lambda)

前端之家收集整理的这篇文章主要介绍了python(filter, map, reduce, lambda)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. filter

       str = ['a','b','c','d']
       def fun1(s): return s if s != 'a' else None
       ret = fileter(func,str)
       print ret
  2. map

       str = ['a','d']
       def func2(s): return s + '.txt'
       ret = map(fun2,str)
       print ret
  3. reduce

       def adda(x,y): return x + y
       print reduce(ass1,range(1,100))
       print reduce(ass1,100),20)
  4. lambda

       g = lambda s: s + '.fsh'
       print g('haha')
       print (lambda x: x*2)(3)    
原文链接:https://www.f2er.com/note/422531.html

猜你在找的程序笔记相关文章