[Python-Dev] setdefault's second argument
Wolfgang Lipp
paragate at gmx.net
Tue Aug 30 20:37:10 CEST 2005
On Tue, 30 Aug 2005 18:14:55 +0200, Tim Peters <tim.peters at gmail.com>
wrote:
>>>> d = {}
>>>> d.setdefault(666)
>>>> d
> {666: None}
>
> just doesn't seem useful. In fact, it's so silly that someone calling
> setdefault with just one arg seems far more likely to have a bug in
> their code than to get an outcome they actually wanted. Haven't found
reminds me of dict.get()... i think in both cases being explicit::
beast = d.setdefault( 666, None )
beast = d.get( 666, None )
just reads better, allthemore since at least in my code what comes
next is invariably a test 'if beast is None:...'. so
beast = d.setdefault( 666 )
if beast is None:
...
and
beast = d.get( 666 )
if beast is None:
...
a shorter but a tad too implicit for my feeling.
_wolf
More information about the Python-Dev
mailing list