Python List Comprehensions

List comprehensions in Python provide a more concise way to generate a list of values.

Let’s first take a look at a more verbose way to generate a list of new elements. In the below code we iterate over a range of numbers three through nine and create a new list, cubed_values, containing each number cubed.

cubed_values = []
for num in range(3, 10):
cube = num**3
# [27, 64, 125, 216, 343, 512, 729]