Generation from a List in Python
Instead of a range of numbers for generating a list, you can also use another list.
Let's create a list whose elements will be the numbers from the second list, raised to the square:
lst = [i ** 2 for i in [1, 2, 3]]
print(lst) # will output [1, 4, 9]
Given a list:
lst = [1, 2, 3, 4, 5]
Using comprehension, write the squares of the elements of the first list into a new list.
Given a list:
lst = [1, 3, 5, 7, 9]
Using comprehension, write the elements of the first list multiplied by
the number 3 into a new list.