proxy pattern if __name__ ="__main__"calculator calculatorproxy(rawcalculator()start_time time time(fib_sequence [calculator fib(xfor in range( )end_time time time(print"calculating the list of {fibonacci numbers took {secondsformatlen(fib_sequence)end_time start_time must admitthis is not trivial piece of codebut let' step through it and see what is happening firstwe have the rawcalculator classwhich is our imagined calculation object at the momentit only contains the fibonacci calculationbut you could imagine it containing many other recursively defined series and sequences as beforethis method uses recursive call nextwe define closure that wraps the function callbut let' leave that for later finallywe have the calculatorproxy classwhich upon initialization takes the target object as parametersets an attribute on the proxy objectand then proceeds to override the fib method of the target object with memoized version of the fib method whenever the target object calls its fib(methodthe memoized version gets called nowthe memoize function takes function as parameter nextit initializes an empty dictionary we then define function that takes list of argumentsgets the name of the function passed to itand creates tuple containing the function name and received arguments this tuple then forms the key to the __cache dictionary the value represents the value returned by the function call the memoized function first checks if the key is already in the cache dictionary if it isthere is no need to recalculate the valueand the value is returned if the key is not foundthe original function is calledand the value is added to the dictionary before it is returned