[Tutor] Setting thresholds in a compact way

Richard Damon Richard at Damon-Family.org
Wed Jan 1 17:45:54 EST 2020


On 1/1/20 5:27 PM, boB Stepp wrote:
> On Wed, Jan 1, 2020 at 2:08 PM Mats Wichmann <mats at wichmann.us> wrote:
>
>> As others have said, I think the if/elif sequence would be fine for
>> this, although it will look ugly if you have too many different buckets.
> Is there any sensible/better thing to do if one is stuck with a long
> sequence of "if" conditions?  I seem to recall some discussion on this
> topic on the main list, but do not recollect anything gaining a
> consensus as to best practice.
>
> HAPPY NEW YEAR TO YOU AND YOURS!!!
>
IF you DO have a very long list, or otherwise want a data driven design, 
you could build a list of tuples, the tuples specifying the range and 
value, and search that list for the entry you want. If you build the 
list in a sorted order, you could binary search the list, and/or make it 
just hold the upper bounds.

-- 
Richard Damon



More information about the Tutor mailing list