The rap against "while True:" loops
Terry Reedy
tjreedy at udel.edu
Sat Oct 17 18:17:36 EDT 2009
Paul Rubin wrote:
> 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
Yes, the motivation was to reduce 4 lines to 1 line for a common use
case, and not because of any sense of 'inappropriateness'.
tjr
More information about the Python-list
mailing list