Loading...

The First Class Function

A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.

Domain
Python
Difficulty
medium
Seniority
mid, senior

Problem

Demonstrate that Python functions are first-class objects. Write a function apply_twice(f, x) that applies a given function f to x, then applies it again to the result, returning the final value. Then write a function compose(f, g) that returns a new function which applies g first then f. Return the results from a test batch.

Practice This Problem

Solve this Python problem with real code execution. DataDriven runs your Python code in a sandboxed Docker environment and grades it instantly.