def countcalls(counts):
 def decorate(func):
  func_name = func.func_name
  counts[func_name] = 0
  def call(*args, **kwds):
   counts[func_name] += 1
   return func(*args, **kwds)
  call.func_name = func_name
  return call
 return decorate

def countcalls ( counts ) : def decorate ( func ) : func_name = func . func_name counts [ func_name ] = 0 def call ( * args , ** kwds ) : counts [ func_name ] += 1 return func ( * args , ** kwds ) call . func_name = func_name return call return decorate
decorator to count calls to a function .