The rap against "while True:" loops

Tim Rowe digitig at
Wed Oct 21 03:11:28 CEST 2009

2009/10/20 Hendrik van Rooyen <hendrik at>:

> So if you want to sum stuff where there are a lot of keys, but only a few
> values per key - say between one and ten, then it would be faster to look
> before you leap.
> On the other hand, if there are relatively few keys and tens or hundreds of
> values per key, then you ask for forgiveness.
> And if you don't  know what the data is going to look like, then you should
> either go into a catatonic state, or take to the bottle, as the zen of python
> states that you should refuse the temptation to guess.

Might I respectfully suggest that in *all* cases you do whatever is
*clearest*, then switch to the other one if and only if performance is
unacceptable *and* profiling reveals this to be the bottleneck? That
avoids your deadlock (or is it livelock?) state.

Tim Rowe

More information about the Python-list mailing list