The rap against "while True:" loops

Paul Rubin http
Sat Oct 17 16:13:11 EDT 2009


aahz at pythoncraft.com (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



More information about the Python-list mailing list