30 Aug
2005
30 Aug
'05
7:45 p.m.
On Tue, 30 Aug 2005 20:55:45 +0200, Tim Peters
[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