[Tutor] Setting thresholds in a compact way

Robert Alexander gogonegro at gmail.com
Wed Jan 1 11:20:08 EST 2020


Dear friends,
First of all let me wish a great 2020 for all of you kind souls and seekers
of knowledge :)

I am trying to setup a varying time.sleep value (in house) depending on a
priorly determined threshold.

If threshold <= .9 AND > .8 then sleep should be 6 hours
if threshold <= 0.8 AND > .4 then sleep should be 4 hours
if threshold <= .4 AND > .1 then sleep should be 3 hours
if threshold <= .1 then sleep should be set to 1 hour

Instead of a complex/lengthy series of (nested?) if/ands based on the
above, I was wondering if I could declare a dictionary such as:

sleep_thresholds_hours = {.9:6, .8:4, .4:3, .1:1}

And then use some sort of single statement to set the sleep_time to the the
proper value.

Not even quite sure that using floats (albeit single decimal) as dictionary
keys will be ok.

Getting old and in 2020 even older and my brain fogged by too much food :)

Thanks in advance


More information about the Tutor mailing list