Dev Helpers
← Back

Apply stock deltas without changing the original ledger

Apply stock deltas without changing the original ledger using Python lists and dictionaries.

Open this example in the interactive library

Source code

from collections import Counter
ledger = Counter(pen=5, pad=2)
revised = ledger.copy()
revised.update({'pen': -2, 'clip': 4})
print(dict(revised))

Sample output

{'pen': 3, 'pad': 2, 'clip': 4}