MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / increment_with_report

Function increment_with_report

example_code/item_048.py:79–91  ·  view source on GitHub ↗
(current, increments)

Source from the content-addressed store, hash-verified

77
78print("Example 4")
79def increment_with_report(current, increments):
80 added_count = 0
81
82 def missing():
83 nonlocal added_count # Stateful closure
84 added_count += 1
85 return 0
86
87 result = defaultdict(missing, current)
88 for key, amount in increments:
89 result[key] += amount
90
91 return result, added_count
92
93
94print("Example 5")

Callers 1

item_048.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected