List comprehension are an extremely useful tool when you want to filter out elements in a list.
There is two major ways to do this
With an if condition
Here is a real-world example
another one that checks for csv files only
With an if else condition
This one is useful when you need to fill in a DataFrame, because it will keep the same length as the original list but return something different depending on your if condition.
Here you are! You now know how to do a list comprehension in Python!
More on fundamentals
If you want to know more about Python fundamentals without headaches... check out the other articles I wrote by clicking just here: