logo
  • 教程列表
  • SO官方文档
  • 过滤
    • 过滤器的基本用法
    • 过滤无功能
    • 过滤为短路检查
    • 补充函数 filterfalse ifilterfalse
  1. StackOverflow 文档
  2. Python Language 教程
  3. 过滤
  4. 过滤无功能

过滤无功能

Created: November-22, 2018

如果函数参数是 None,那么将使用标识函数:

list(filter(None, [1, 0, 2, [], '', 'a']))  # discards 0, [] and ''   
# Out: [1, 2, 'a']

Python 2.x >= 2.0.1

[i for i in [1, 0, 2, [], '', 'a'] if i] # equivalent list comprehension

Python 3.x >= 3.0.0

(i for i in [1, 0, 2, [], '', 'a'] if i) # equivalent generator expression
  • 过滤为短路检查
  • 过滤器的基本用法

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 关于我们
  • 免责声明