Changes

Jump to: navigation, search

OPS435 Python Lab 4

8 bytes added, 10:29, 16 June 2017
PART 4 - List Comprehension
for item in l1:
print(item ** 2)
</source>In order to store these results (i.e. squares) for later use, you would have to create a new list and append the squares to it. This will generate a new list that contains squared values in the same positions of the first list. In this way, you are using an existing list in order to create a new (larger) list.<br><br>
:#To demonstrate, issue the following:<source>
l1 = [1, 2, 3, 4, 5]
13,420
edits

Navigation menu