[Steven Bethard] > * Should default_factory be an argument to the constructor? The three > answers I see: > > - "No." I'm not a big fan of this answer. Since the whole point of > creating a defaultdict type is to provide a default, requiring two > statements (the constructor call and the default_factory assignment) > to initialize such a dictionary seems a little inconvenient. You still have to allow assignments to the default_factory attribute to allow the factory to be changed: dd.default_factory = SomeFactory If it's too much effort to do the initial setup in two lines, a classmethod could serve as an alternate constructor (leaving the regular contructor fully interchangeable with dicts): dd = defaultdict.setup(list, {'k1':'v1', 'k2:v2'}) or when there are no initial values: dd = defaultdict.setup(list) Raymond
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