[Python-Dev] defaultdict proposal round three (original) (raw)
Steven Bethard steven.bethard at gmail.com
Tue Feb 21 00:14:27 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, Dan Gass <dan.gass at gmail.com> wrote:
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.defaultfactory = lambda k : list() d.defaultfactory = lambda k : 0
Guido's currently backing "a subclass that implements getitem() calling on_missing() and on_missing() ... calling default_factory unless it's None". I think for 90% of the use-cases, you don't need a key argument. If you do, you should subclass defaultdict and override the on_missing() method.
STeVe
Grammar am for people who can't think for myself. --- Bucky Katt, Get Fuzzy
- Previous message: [Python-Dev] defaultdict proposal round three
- Next message: [Python-Dev] defaultdict proposal round three
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]