Barry Warsaw wrote:
> However, .setdefault() is a horrible name because it's not clear from  
> the name that a 'get' operation also happens.

The return value of .setdefault() could be changed to None, then the name 
would be correct.

And then a helper function could fill the current use case of returning the 
added abject at the same time.

 >>> d = {}
 >>> def setget(setter, getter, vars):
...   setter(*vars)
...   return getter(*vars)
...
 >>> setget(d.setdefault, d.get, ('foo', [])).append(7)
 >>> d
{'foo': [7]}
 >>> setget(d.setdefault, d.get, ('foo', [])).append(8)
 >>> d
{'foo': [7, 8]}

Now if this could be made to be more general so it worked with with other 
objects it might really be useful. ;-)

Cheers,
    Ron
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to