order_avalanche()
Order debts for the avalanche method (highest APR first).
Usage
order_avalanche(debts)From the Managing Debt chapter.
Parameters
debts: list[dict[str, Any]]-
A list of dicts, each with a numeric
aprkey.
Returns
list of dict-
A new list, sorted by
aprfrom highest to lowest. Ties keep their original order.
Raises
TypeError-
If
debtsis not a list of dicts, or anapris not numeric. ValueError-
If a debt has no
aprkey, or anapris missing.
See Also
- order_snowball()
-
Smallest balance first.
Examples
>>> from perfinpy import order_avalanche
>>> 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_avalanche(debts)][‘Card B’, ‘Card A’, ‘Card C’]