[Python-Dev] defaultdict proposal round three (original) (raw)
Dan Gass dan.gass at gmail.com
Tue Feb 21 00:08:07 CET 2006
- Previous message: [Python-Dev] defaultdict proposal round three
- Next message: [Python-Dev] defaultdict proposal round three
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2/20/06, Raymond Hettinger <raymond.hettinger at verizon.net> wrote:
An alternative is to have two possible attributes: d.defaultfactory = list or d.defaultvalue = 0 with an exception being raised when both are defined (the test is done when the attribute is created, not when the lookup is performed). Why not have the factory function take the key being looked up as an argument? Seems like there would be uses to customize the default based on the key. It also forces you to handle list factory functions and constant factory functions (amongst others) to be handled the same way:
d.default_factory = lambda k : list() d.default_factory = lambda k : 0
Dan Gass -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-dev/attachments/20060220/2f99b73a/attachment.htm
- Previous message: [Python-Dev] defaultdict proposal round three
- Next message: [Python-Dev] defaultdict proposal round three
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]