Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python lambda expressions code

Practice writing concise lambda expressions for direct calls, sorting, closures, and predicates.

Intermediate ~8 min read

Challenge 1

Create a lambda that doubles value.

python Your answer
double = 

print(double(6))

Press Ctrl⌘Enter to check your answer

Challenge 2

Use a lambda to sort words by length.

python Your answer
words = ["pear", "banana", "fig", "apple"]
words.sort(key=)
print(words)

Press Ctrl⌘Enter to check your answer

Challenge 3

Return a lambda that adds amount to value.

python Your answer
def make_adder(amount):
    return 

add_five = make_adder(5)
print(add_five(8))

Press Ctrl⌘Enter to check your answer

Challenge 4

Create a lambda that returns True when n is even.

python Your answer
is_even = 

print(is_even(8))
print(is_even(7))

Press Ctrl⌘Enter to check your answer