Python Programming - Lambda Functions
Exercise : Lambda Functions - General Questions
- Lambda Functions - General Questions
41.
When using the
sorted()
function with a lambda function to sort a list of strings, how can the sorting be case-insensitive?
Answer: Option
Explanation:
Using
lower()
inside the lambda function converts strings to lowercase, achieving case-insensitive sorting.
42.
Which built-in function can be used with a lambda function to find the sum of values in an iterable?
Answer: Option
Explanation:
The
sum()
function can be used with a lambda function to find the sum of values in an iterable based on the lambda function's criteria.
43.
What does the following lambda function do?
lambda x: x if x % 2 == 0 else None
Answer: Option
Explanation:
The lambda function filters out even numbers by returning None for them.
44.
What is the primary advantage of using a lambda function over a regular function?
Answer: Option
Explanation:
Lambda functions are often used for short, simple tasks due to their concise syntax, allowing them to be written in a single line.
45.
What is the output of the following code?
items = [1, 2, 3, 4, 5]
result = list(map(lambda x: x * 3, items))
Answer: Option
Explanation:
The
map()
function applies the lambda function to multiply each item by 3.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers