Dictionary from list?

Tim Peters tim.one at home.com
Sat Oct 27 12:53:43 EDT 2001


[James_Althoff at i2.com]
> ...
> isn't this a reasonable place to take advantage of the new 2.2 class
> methods and provide:
>
> dictionary.newFromList([k,v,...])
>
> (or some other shorter/more-appealing method name of preference)?

I don't think so, simply because it would make dictionary unique.  Python
already had str(), unicode(), int(), long(), float(), complex(), list() and
tuple() builtins, and adding dictionary() and file() to 2.2 was thus natural
(for Python).

> I think class methods provide a nice way to introduce alternative
> "constructors" without having to add special modules for the sole
> purpose of serving as a home for module-based constructor-esque
> functions

We're not adding any such modules.

> and without having to add more builtin functions, etc.

If the name "dictionary" was presumed available in

    dictionary.newFromList()

above without first having to import some special module, then "dictionary"
was perforce a builtin name anyway, function or not.  I know you focus on
the "function" part, but it's the "builtin" part that matters <wink>.

> (Guilty as charged of more Smalltalk-hardwiring-of-the-brain thinking ;-)

I've heard that Smalltalk's class-method constructors work very well there.
Python took a different approach long ago, and it also appears to work well.





More information about the Python-list mailing list