Challenge - 5 Problems
Lambda Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of a lambda function used with map
What is the output of this code that uses a lambda function with
map to double numbers?Python
numbers = [1, 2, 3, 4] doubled = list(map(lambda x: x * 2, numbers)) print(doubled)
Attempts:
2 left
๐ก Hint
Think about what the lambda function does to each number in the list.
โ Incorrect
The lambda function takes each number and multiplies it by 2. The map applies this to all numbers, so the output is a list of doubled values.
๐ง Conceptual
intermediate1:30remaining
Why use lambda functions instead of regular functions?
Which of the following best explains why lambda functions are used in Python?
Attempts:
2 left
๐ก Hint
Think about the difference between naming a function and using a quick inline function.
โ Incorrect
Lambda functions let you write small functions without giving them a name, which is useful for short tasks like sorting or mapping.
โ Predict Output
advanced2:00remaining
Output of sorting with a lambda key
What is the output of this code that sorts a list of tuples by the second item using a lambda function?
Python
pairs = [(1, 'b'), (2, 'a'), (3, 'c')] pairs.sort(key=lambda x: x[1]) print(pairs)
Attempts:
2 left
๐ก Hint
The lambda function picks the second element of each tuple for sorting.
โ Incorrect
The list is sorted by the second element of each tuple alphabetically: 'a', 'b', 'c'.
๐ง Debug
advanced1:30remaining
Identify the error in lambda usage
What error does this code raise and why?
Python
func = lambda x, y: x + y print(func(2))
Attempts:
2 left
๐ก Hint
Check how many arguments the lambda expects and how many are given.
โ Incorrect
The lambda expects two arguments but only one is provided, causing a TypeError.
๐ Application
expert2:30remaining
Using lambda to filter and transform a list
Which option produces the list of squares of even numbers from 0 to 9 using lambda functions?
Attempts:
2 left
๐ก Hint
First select even numbers, then square them.
โ Incorrect
Option D first filters even numbers, then maps to their squares, producing [0, 4, 16, 36, 64]. Others mix order or logic incorrectly.