(current, increments)
| 77 | |
| 78 | print("Example 4") |
| 79 | def 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 | |
| 94 | print("Example 5") |