question 100 Fundamentals Integration · hard
End-of-day balances and overdrafts
A bank statement is a list of (date, description, amount) transactions in date order; money in is positive, money out negative. Starting from opening, return a tuple of two lists: the balance at the end of each date that has transactions, as (date, balance), and the dates that ended overdrawn (below 0). A balance that dips below 0 during a day but recovers by the end of it doesn't count.
Function
daily_balances(transactions, opening)transactionsa list of
(date, description, amount) tuples, dates in order, several per date allowedReturns
(balances, overdrawn): [(date, end_balance), ...] and [date, ...]Must notchange
transactionsExamples
calldaily_balances([('05-01', 'salary', 1800), ('05-01', 'rent', -1200), ('05-02', 'groceries', -86.4), ('05-03', 'phone', -45), ('05-03', 'transfer in', 30)], -150)returns([('05-01', 450), ('05-02', 363.6), ('05-03', 348.6)], [])
calldaily_balances([('06-01', 'card', -20), ('06-02', 'refund', 5)], 10)returns([('06-01', -10), ('06-02', -5)], ['06-01', '06-02'])
calldaily_balances([], 100)returns([], [])