1- def custom_power (x = 0 , / , e = 1 ):
2- """A lambda function that calculates x raised to the power of e."""
3- return (lambda x , e : x ** e )(x , e ) #Direct Calculation
1+ custom_power = lambda x = 0 , e = 1 : x ** e
42
53def custom_equation (x : int = 0 , y : int = 0 , / , a : int = 1 , b : int = 1 , * , c : int = 1 ) -> float :
64
@@ -19,18 +17,19 @@ def custom_equation(x: int = 0, y: int = 0, /, a: int = 1, b: int = 1, *, c: int
1917 return (x ** a + y ** b ) / c
2018
2119from collections import defaultdict
20+ import inspect
2221
2322call_count = defaultdict (int )
2423
25- def fn_w_counter ()-> tuple [ int , dict [str , int ]] :
24+ def fn_w_counter ()-> ( int , dict [str , int ]) :
2625 """A function that counts the number of calls."""
27- call_count = defaultdict ( int )
28-
29- def wrapper () -> tuple [ int , dict [ str , int ]]:
30- import inspect
31- caller_name = inspect . stack ()[ 1 ]. function
32- call_count [ caller_name ] += 1
33- total_calls = sum (call_count .values ())
34- return total_calls , dict ( call_count )
35-
36- return wrapper
26+ caller_name = inspect . stack ()[ 1 ]. function # Get the name of the calling function
27+
28+ # Increment the global counter
29+ call_count [ caller_name ] += 1
30+
31+ # Calculate the total number of calls
32+ total_calls = sum (call_count .values ())
33+
34+ # Return the total call count and the call counts for each function
35+ return total_calls , dict ( call_count )
0 commit comments