Python Language Filter Filter without function

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

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']
Python 2.x2.0.1
[i for i in [1, 0, 2, [], '', 'a'] if i] # equivalent list comprehension
Python 3.x3.0.0
(i for i in [1, 0, 2, [], '', 'a'] if i) # equivalent generator expression


Got any Python Language Question?