Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 4

187 bytes added, 10:42, 16 June 2017
PART 4 - List Comprehension
l1
l2
</source>:#The above ''map ()'' function requires a another function, and as well as a list. This meant means that before using (calling) the map() could be used a function needed , that other function would have to be have been defined earlier in the script. This entire process can be avoided through the use of '''anonymous functions'''. This is the ability to create a simple function without defining it, and pass it off for useon to other function calls. Below we You will use the the '''lambdaanonymous function''', which will return a function, and we that you can use in that function immediately(i.e. without having to declare it in your script). The function takes 1 argument (called: x), and it will perform a single operation on x, square itthat value.<br><br>:#To demonstrate, issue the following:<source>
square = lambda x: x ** 2
l1 = [1,2,3,4,5]
13,420
edits