filter过滤器与map映射

filter过滤器
>>> list(filter(None,[0,1,2,True,False]))
[1, 2, True]
filter的作用就是后面的数据按照前面的表达式运算后,得出为False则去掉,返回所有为True的值。
#举例找出0—100所有的奇数
def myfun(x):
  return x%2
temp=range(100)
list(filter(myfun,temp))
#该例子也可以用一行代码结束
list(filter(lambda x:x%2,range(100)))
map映射
>>> list(map(lambda x:x*2,range(10)))
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
map是将后面所有的数字按照前面的函数计算得出的结果,直到后面的序列运算完毕。
原文地址:https://www.cnblogs.com/themost/p/6358899.html