The rap against "while True:" loops

Aahz aahz at
Sat Oct 17 22:27:03 CEST 2009

In article <7xmy3peq3s.fsf at>,
Paul Rubin  <> wrote:
>aahz at (Aahz) writes:
>> Standard Python idiom:
>> try:
>>     d[key] += value
>> except KeyError:
>>     d[key] = value
>> Maybe you need to re-think "appropriate".
>But more recent style prefers:
>   d = collections.defaultdict(int)
>   ...
>   d[key] += value

That was a trivial example; non-trivial examples not addressed by
defaultdict are left as an exercise for the reader.
Aahz (aahz at           <*>

"To me vi is Zen.  To use vi is to practice zen.  Every command is a
koan.  Profound to the user, unintelligible to the uninitiated.  You
discover truth everytime you use it."  --reddy at

More information about the Python-list mailing list