⊗pyPmCoLG 27 of 128 menu

Generate from a list in Python

Instead of a range of numbers, you can use another list to generate a list.

Let's create a list whose elements will be the numbers from the second list squared:

lst = [i ** 2 for i in [1, 2, 3]] print(lst) # [1, 4, 9]

Given a list:

lst = [1, 2, 3, 4, 5]

Use inclusion to write the squares of the elements of the first list into a new list.

Given a list:

lst = [1, 3, 5, 7, 9]

Using inclusion, write into a new list the elements of the first list multiplied by 3.

enru