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是将后面所有的数字按照前面的函数计算得出的结果,直到后面的序列运算完毕。

相关文章:

  • 2022-01-03
  • 2021-09-28
  • 2021-12-29
猜你喜欢
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-16
  • 2021-11-23
  • 2021-11-23
相关资源
相似解决方案