Ad
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Hi, actually, function 1 is called when python interpret the line that contain @function1. So it call it like this: function1(function2). This is redefining the function2 to what function1 returns.
    If function1 return function2, later calls to function2 will indeed execute the code of function 2.

    In the case of this solution, as memoized function is returning the wrapped function, later calls to fibonacci actually will call wrapped function (that has inside it the original fibonacci function).

    So, when the interpreter reads the line "@memoized", it calls the memoized function (like this memoized(fibonnacci) ). Then it creates the empty dictionary and return the wrapper function. This way the dictionary is not redefined to empty at every call to fibonacci function.
    The dictionary is still saved at the memory and the wrapper function has a reference to it.
    Later call to fibonacci function will indeed call the wrapper function because the memoized functoin redefined it to wrapper function.

  • Default User Avatar

    Hey guy, maibe you need to study some math too, before some exercises. To rank up you will need basic math generally that basics that is need to start to study computer science.
    I would recomend you to go to https://khanacademy.org/ and start learning the basics meanwhile you study how to program.
    Just trying to help.