Python Programming - Lambda Functions
Exercise : Lambda Functions - General Questions
- Lambda Functions - General Questions
36.
What is the purpose of the
functools.reduce()
function when used with a lambda function?
Answer: Option
Explanation:
functools.reduce()
successively applies the lambda function to accumulate values in an iterable.
37.
What is the output of the following code?
numbers = [1, 2, 3, 4, 5]
result = list(filter(lambda x: x % 2 == 0, numbers))
print(result)
Answer: Option
Explanation:
The
filter()
function with the lambda filters even numbers from the list.
38.
Which of the following built-in functions can be used to find the length of a list of strings using a lambda function?
Answer: Option
Explanation:
The
len()
function can be used with a lambda function to find the length of a list of strings.
39.
What does the following lambda function accomplish?
lambda x: x.upper()
Answer: Option
Explanation:
The lambda function
lambda x: x.upper()
converts a string to uppercase.
40.
In Python, what is the purpose of the
sorted()
function when used with a lambda function?
Answer: Option
Explanation:
The
sorted()
function is used to create a sorted list from the elements of an iterable, with sorting criteria defined by the lambda function.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers