""" Demonstration of list comprehensions"""

# code to create a new list by making some modification
# to each element in an old list
L = list(range(1, 101))  # 1 to 100
# want a new list with each number doubled
new_L = []
for value in L:
    new_L.append(value * 2)

# instead, use a list comprehension
# collapse the loop above into one statement
new_L2 = [value * 2 for value in L]
print(new_L == new_L2)

# code to create a new list as a subset of an old list
# based on some criteria
another_L = []
for value in L:
    if value % 3 == 0:
        another_L.append(value)

another_L2 = [value for value in L if value % 3 == 0]
print(another_L == another_L2)
