how to avoid checking the same condition repeatedly ?

Neil Cerutti neilc at norwich.edu
Tue Oct 29 09:44:51 EDT 2013


On 2013-10-28, Nobody <nobody at nowhere.com> wrote:
> On Mon, 28 Oct 2013 09:50:19 +0000, Wolfgang Maier wrote:
>> So my question is: is there an agreed-upon generally best way
>> of dealing with this?
>
> Yes. Just leave the test inside the loop.
>
> If you're sufficiently concerned about performance that you're
> willing to trade clarity for it, you shouldn't be using Python
> in the first place.

When you detect a code small, as Wolfgang did, e.g., "I'm
repeating the same exact test condition in several places," you
should not simply ignore it, even in Python.

-- 
Neil Cerutti



More information about the Python-list mailing list