Pre-PEP: Dictionary accumulator methods
Colin J. Williams
cjw at sympatico.ca
Sun Mar 20 13:10:39 EST 2005
Paul Rubin wrote:
> "El Pitonero" <pitonero at gmail.com> writes:
>
>>What about no name at all for the scalar case:
>>
>>a['hello'] += 1
>>a['bye'] -= 2
>
>
> I like this despite the minor surprise that it works even when
> a['hello'] is uninitialized.
+1
and if the value is a list:
a['hello']= [1, 2, 3]
a['hello']+= [4] # adding the brackets is a lot simpler than
typing append or extend.
Any user is free to add his/her own subclass to handle defaults.
Colin W.
More information about the Python-list
mailing list