Filter without function

suggest change

If the function parameter is None, then the identity function will be used:

list(filter(None, [1, 0, 2, [], '', 'a']))  # discards 0, [] and ''   
# Out: [1, 2, 'a']
[i for i in [1, 0, 2, [], '', 'a'] if i] # equivalent list comprehension
(i for i in [1, 0, 2, [], '', 'a'] if i) # equivalent generator expression

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents