Changes

Jump to: navigation, search

OPS435 Python Lab 4

162 bytes added, 10:27, 16 June 2017
PART 4 - List Comprehension
:'''Perform the Following Steps'''
:#Lets Let's start with by creating a list and then applying some function functions to each item in that list. Issue the following to create a list. The below will print out and then display the square of for each item.within that list:<source>
l1 = [1, 2, 3, 4, 5]
for item in l1:
print(item ** 2)
</source>:#To 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. This is In this way, you are using an existing list in order to create a new (larger) list.:#To demonstrate, issue the following:<source>
l1 = [1, 2, 3, 4, 5]
l2 = []
13,420
edits

Navigation menu