Program - function to attach counter to function


Topic: Program - function to attach counter to function

Solution

def attach_counter(fn: "Function"):
    count = 0
    def inner(*args, **kwargs):
        nonlocal count
        count += 1
        return fn(*args, **kwargs)
    return inner



List all Python Programs