Tim Rowe a écrit :
2008/12/12 Kirk Strauser <k...@daycos.com>:
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
Yes, once it's changed from a dictionary to tuples it becomes easier,
doesn't it? D'oh!
<comment>
A sequence of pairs and a dict are _almost_ interchangeable (mmm... is
that the correct word ?) representations of a same data set[1] - the
main difference being ordering. If ordering matters, choose a sequence
of pairs as main representation - you can easily build a dict from it
if/when you need it.
[1]
>>> d = dict(a=1, b=2, c=3)
>>> dict(d.items()) == d
True
>>>
</comment>
--
http://mail.python.org/mailman/listinfo/python-list