List comprehensions

Here is a simple python for loop: Notice that append() function is called to add elements to the list. Let’s write the same using List comprehension: The simplest way to understand why list comprehensions are faster is by noticing that in the first example, append() function is called explicitly. But in list comprehension, it is … Continue reading List comprehensions