A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2005-August/055851.html below:

[Python-Dev] setdefault's second argument

[Python-Dev] setdefault's second argument [Python-Dev] setdefault's second argumentWolfgang 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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4