List Comprehensions
We'll cover the following...
We'll cover the following...
A list comprehension provides a compact way of mapping a list into another list by applying a function to each of the elements of the list.
① To make sense of this, look at it from right to left. a_list is the list you’re mapping. The Python interpreter loops through a_list one element at a time, temporarily assigning the value of each element to the variable elem. Python then applies the function elem * 2 and appends that result to the returned list.
② A list comprehension creates a new list; it ...