Ever use list comprehension in Python?
If not here is very beautiful use of list comprehension in Python which will make your code more neat and readable.
First of all what is list comprehension?
List comprehension is a syntax, list comprehension offer a shorter syntax when you want to create a new list based on the values of an existing list.
Here is the SYNTAX for it
[expression for item in iterable if condition == True]
Below I have shown two examples
One without using list comprehension and another with list comprehension.
Top comments (1)
Awesome 😎