Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Week04/fn_w_counter_gamze_kilinc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def fn_w_counter() -> tuple[int, dict[str, int]]:
"""
Counts function calls with caller information.

:return: A tuple containing total call count and a dictionary
mapping caller names to their call counts.
"""
if not hasattr(fn_w_counter, "_total_calls"):
fn_w_counter._total_calls = 0
fn_w_counter._callers = {}

caller = __name__

fn_w_counter._total_calls += 1
fn_w_counter._callers[caller] = fn_w_counter._callers.get(caller, 0) + 1

return fn_w_counter._total_calls, fn_w_counter._callers