List Comprehension An Overview

List comprehensions are very widely used in python. They are an elegant way to define and create a list in python.
Let's say that you have a list of numbers and you want to create a new list of numbers that’s the same as the old list, except that each number has 1 add to it. We can do that in two ways using for loop and list comprehension.
First, let’s talk about how we can do that using for loop. To do so we can initialize a new empty list, loop through the old list, add 1 to each entry and append all new values to the new list.

But for loops are inefficient both computationally and in terms of coding time and space, particularly when we can do all this in a single line of code. Hence list comprehension comes into the picture. List comprehension is used when there are multiple variables.

List comprehension can be written not just only on list but even range. Basically list comprehension uses a single line of code instead of for loops that use multiple lines.
List comprehensions can only be written only on an iterable or iterators. They consist of the output expression and they can also consist the conditions-the if-else conditions.