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

  • 關於本站
  • 免責聲明