Last Updated: December 6, 2025
30 quizzes
Complete the code to apply a function to every element and build a new list of squares.
squared_values = list(map(, [1, 2, 3, 4]))Click an option to fill the blank:
Complete the code so that the function reference, not its result, is stored for later use.
stored = Click an option to fill the blank:
Complete the expression to convert an immutable list of scores into a new sorted list without changing the original.
sorted_scores = (scores)Click an option to fill the blank:
In functional programming, what does it mean that functions are first-class citizens in Python?
Which property is essential for a function to be considered pure?
Which built-in function best represents a higher-order function?
You want to pre-fill some arguments of a function and get a new callable. Which tool should you use?
Currying transforms a function with multiple arguments into what?
Which Python type is immutable?
Why are pure functions easier to test?
Which statement about lambda functions is true?
You have an immutable configuration stored as a tuple of values. How do you update it functionally?
Which example best illustrates a higher-order function returning another function?
Order the steps to create and use a higher-order function that filters even numbers from a list.
Drag and drop to reorder, or use the arrows.
Order the steps to implement a curried adder that adds three numbers one by one.
Drag and drop to reorder, or use the arrows.
What is the output of this code using a pure function to transform data?
1def double_price(price):
2 return price * 2
3
4prices = [10, 20, 30]
5new_prices = list(map(double_price, prices))
6print(new_prices[-1])What is the output when using filter with a lambda?
1numbers = [1, 2, 3, 4, 5]
2result = list(filter(lambda value: value > 3, numbers))
3print(len(result))What is the output when creating a partially applied function?
1from functools import partial
2
3def power(base, exponent):
4 return base ** exponent
5
6square = partial(power, exponent=2)
7print(square(5))What is the output of this curried multiplier example?
1def multiply_by(a):
2 def inner(b):
3 return a * b
4 return inner
5
6double = multiply_by(2)
7print(double(7))What is the output when working with an immutable string?
1title = "developer"
2new_title = title.upper()
3print(title == new_title)This function is meant to be a pure function that applies a tax rate to a price list. Find the bug that breaks purity.
Click on the line(s) that contain the bug.
tax_rate = 0.2 def apply_tax(prices): taxed = [] for price in prices: taxed_price = price + price * tax_rate prices.append(taxed_price) taxed.append(taxed_price) return taxedThis code aims to demonstrate immutability using a tuple of coordinates. Find the bug.
Click on the line(s) that contain the bug.
def move_point(point, dx, dy): # point is expected to be an (x, y) tuple point[0] = point[0] + dx point[1] = point[1] + dy return point start = (0, 0)end = move_point(start, 5, 3)Match each functional programming concept with its description.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each Python tool with how it supports functional programming.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the pure function that returns a new list of title-cased names without modifying the original list.
def normalize_names(raw_names): clean_names = for raw_name in raw_names: clean_names.append() return clean_namesClick an option to fill blank 1:
Complete the code to use a higher-order function that filters active users based on a predicate.
def is_active(user_record): return user_record["active"]users = [{"name": "A", "active": True}, {"name": "B", "active": False}]active_users = list((, users))Click an option to fill blank 1:
Complete the code to create a partial function that always calls the logging function with level='INFO'.
from functools import def log(level, message): return f"[{level}] {message}"info_log = (log, level="INFO")Click an option to fill blank 1:
Complete the code so that updating a configuration uses immutability by creating a new dict instead of changing the original.
def with_timeout(config, timeout_seconds): new_config = (config) new_config["timeout"] = timeout_seconds return Click an option to fill blank 1:
Click the line that introduces a side effect and makes the function impure.
Click on the line to select.
log_messages = [] def compute_total(prices): total = sum(prices) log_messages.append(f"Computed total: {total}") return totalClick the line that incorrectly attempts to mutate an immutable string.
Click on the line to select.
message = "hello"chars = list(message)chars[0] = 'H'message = ''.join(chars)print(message)