198
edits
Changes
→PART 4 - List Comprehension
l2
</source>
:#The above map function requires a function, and a list. This meant that before map() could be used a function needed to be 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 use. Below we will use lambda, which will return a function, and we can use that function immediately. The function takes 1 argument x, and it will perform a single operation on x, square it.<source>
square = lambda x: x ** 2
l1 = [1,2,3,4,5]