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/055860.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 21:45:23 CEST 2005
On Tue, 30 Aug 2005 20:55:45 +0200, Tim Peters <tim.peters at gmail.com>  
wrote:

> [Wolfgang Lipp]
>> reminds me of dict.get()... i think in both cases being explicit::
>>
>>     beast = d.setdefault( 666, None )
>>         ...
>
> Do you actually do this with setdefault()?

well, actually more like::

     def f( x ): return x % 3
     R = {}
     for x in range( 30 ):
         R.setdefault( f( x ), [] ).append( x )

still contrived, but you get the idea. i was really excited when finding  
out
that d.pop, d.get and d.setdefault work in very much the same way in  
respect
to the default argument, and my code has greatly benefitted from that. e.g.

     def f( **Q ):
         myoption = Q.pop( 'myoption', 42 )
         if Q:
             raise TypeError(...)

_w


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