Python Programming - Lambda Functions - Discussion

Discussion Forum : Lambda Functions - General Questions (Q.No. 55)
55.
What is the result of the following code?
numbers = [1, 2, 3, 4, 5]
squared = list(map(lambda x: x ** 2 if x % 2 == 0 else x, numbers))
print(squared)
[1, 4, 3, 16, 5]
[1, 4, 9, 16, 25]
[1, 2, 3, 4, 5]
[1, 2, 9, 4, 25]
Answer: Option
Explanation:
The lambda function squares even numbers and leaves odd numbers unchanged.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.