The rap against "while True:" loops

Paul Rubin http
Sun Oct 18 11:31:19 CEST 2009


Hendrik van Rooyen <hendrik at microcorp.co.za> writes:
> Standard Python idiom:
> 
> if key in d:
>   d[key] += value
> else:
>   d[key] = value

The issue is that uses two lookups.  If that's ok, the more usual idiom is:

  d[key] = value + d.get(key, 0)



More information about the Python-list mailing list