Changes

Jump to: navigation, search

OPS435 Python Lab 4

120 bytes added, 10:33, 16 June 2017
PART 4 - List Comprehension
l1
l2
</source>:#Move the squaring of numbers out into it's own separate function. While the squaring example is Since this may be a simple functionrepetitive task, this example could include it makes more sense to create a more complex function that does more processing on each will append the squares to a new item in the within an existing list.<br><br> :#Issue the following to see how that can be performed:<source>
def square(number):
return number ** 2
l1
l2
</source>:#The '''map ()''' function can be used to apply a function on each item in a list. This is exactly what happened abovein the previous example; however, however it gives much using the ''map()'' function provides for better syntax, and removes the loop, (including the variable that was created inside the loop). This Therefore, using the ''map()'' function will make the your Python script a little more efficient while performing the same task.:#To demonstrate, issue the following:<source>
def square(number):
return number ** 2
13,420
edits

Navigation menu