過濾無功能
如果函式引數是 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