Python Programming - Lambda Functions
Exercise : Lambda Functions - General Questions
- Lambda Functions - General Questions
56.
What is the output of the following code?
items = ['apple', 'banana', 'cherry']
filtered = list(filter(lambda x: 'a' in x, items))
print(filtered)
Answer: Option
Explanation:
The
filter()
function with the lambda filters items containing the letter 'a'.
57.
How can a lambda function be used with the
min()
function to find the minimum length string in a list of strings?
Answer: Option
Explanation:
The
key
parameter is used to specify the lambda function that calculates the length of each string.
58.
What is the purpose of the
reduce()
function when used with a lambda function?
Answer: Option
Explanation:
The
reduce()
function is used to apply the lambda function cumulatively to the items of an iterable.
59.
What does the following lambda function do?
lambda x, y: x + y
Answer: Option
Explanation:
The lambda function adds two numbers.
60.
When using the
sorted()
function with a lambda function to sort a list of tuples, how can you sort based on the second element of each tuple?
Answer: Option
Explanation:
The
key
parameter is used to specify the lambda function that extracts the second element for sorting.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers