At 2008-12-12T18:12:39Z, "Tim Rowe" <digi...@gmail.com> writes:
> Is there a tidy way of making rates and thresholds local to get_rate, > without recalculating each time? I suppose going object oriented is > the proper way. > > #Py3k,UTF-8 > > rates = {0: 0.006, 10000: 0.0085, 25000: 0.0124, 50000: 0.0149, 100000: > 0.0173} > thresholds = list(rates.keys()) > thresholds.sort() > thresholds.reverse() > > def get_rate(balance): > for threshold in thresholds: > if balance >= threshold: > return rates[threshold] > else: > return 0.0 How 'bout: def get_rate(balance): for threshold, rate in ((100000, .0173), (50000, .0149), (25000, .0124), (10000, .0085), (0, .006)): if balance > threshold: return rate return .0 -- Kirk Strauser The Day Companies -- http://mail.python.org/mailman/listinfo/python-list