On Mar 8, 2014, at 7:29 AM, eryksun <eryk...@gmail.com> wrote: > i.e. > > guess < 1 or guess > 100 > > becomes > > not not (guess < 1 or guess > 100) Why a not not? Wouldn’t that just be saying do this because the second not is undoing the first? > > distribute over the disjunction > > not (not (guess < 1) and not (guess > 100)) > > logically negate the comparisons > > not (1 <= guess and guess <= 100) > > finally, write the conjoined comparisons as a chained comparison: > > not (1 <= guess <= 100) > > i.e., guess isn't in the closed interval [1, 100]. > > Anyway, you needn't go out of your way to rewrite the expression using > a chained comparison. The disjunctive expression is actually > implemented more efficiently by CPython's compiler, which you can > verify using the dis module to disassemble the bytecode. I’m not sure what you’re talking about in the above paragraph.
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor