order_snowball()
Order debts for the snowball method (smallest balance first).
Usage
order_snowball(debts)From the Managing Debt chapter.
Parameters
debts: list[dict[str, Any]]-
A list of dicts, each with a numeric
balancekey.
Returns
list of dict-
A new list, sorted by
balancefrom smallest to largest. Ties keep their original order.
Raises
TypeError-
If
debtsis not a list of dicts, or abalanceis not numeric. ValueError-
If a debt has no
balancekey, or abalanceis missing.
See Also
- order_avalanche()
-
Highest APR first.
Examples
>>> from perfinpy import order_snowball
>>> debts = [
... {"name": "Card A", "balance": 1000, "apr": 0.18},
... {"name": "Card B", "balance": 5000, "apr": 0.24},
... {"name": "Card C", "balance": 2000, "apr": 0.15},
... ]
>>> [d["name"] for d in order_snowball(debts)][‘Card A’, ‘Card C’, ‘Card B’]