← Back to challenges

Lambda Expressions All the Way Down

PythonHardfunctional_programminghigher_order_functionsrecursion

Instructions

Create a function which takes a parameter n and returns a function such that it, when called n times, returns the string "innokodakademija".

Examples

lambda_depth(0) ➞ "innokodakademija"

lambda_depth(1)() ➞ "innokodakademija"

lambda_depth(2)()() ➞ "innokodakademija"

type(lambda_depth(2)()) ➞ <class: "function">

Notes

  • num will always be a non-negative integer.
  • If num == 0, return "innokodakademija".
  • If num > 0, return a function.
  • All non-example test cases come in two forms: checking whether lambda_depth(k), after being called k times, returns a string, and checking whether lambda_depth(k) returns a function.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.