[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>  
>>>> 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:

     beast = d.get( 666 )
     if beast is None:

a shorter but a tad too implicit for my feeling.


More information about the Python-Dev mailing list