⊗pyPmCoLG 27 of 128 menu

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.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline