Explanation:
Input List:
The input list is numbers = [1, 2, 3, 4].Lambda Function:
The lambda x: x * 2 function takes each element x from the list and multiplies it by 2.Using map() Function:
The map() function applies the lambda function to each element of the list. Here's the breakdown:- For x = 1: 1 * 2 = 2
- For x = 2: 2 * 2 = 4
- For x = 3: 3 * 2 = 6
- For x = 4: 4 * 2 = 8
Converting to a List:
The result of the map() function is a map object. Using list() converts the map object into a Python list: [2, 4, 6, 8].Output:
The print() function displays [2, 4, 6, 8].
Other Options Explained:
- a) [1, 2, 3, 4]: Incorrect. This would be the original list without applying the lambda function.
- c) map object: Incorrect. The map() function alone returns a map object, but the list() function converts it into a list.
- d) [1, 4, 9, 16]: Incorrect. This would be the result if the lambda function was lambda x: x ** 2 (squares each number).
0 Comments:
Post a Comment