A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-February/061536.html below:

[Python-Dev] defaultdict proposal round three

[Python-Dev] defaultdict proposal round three [Python-Dev] defaultdict proposal round threeRaymond Hettinger python at rcn.com
Tue Feb 21 00:14:13 CET 2006
[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
More information about the Python-Dev mailing list

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