Dictionary from list?

James_Althoff at i2.com James_Althoff at i2.com
Mon Oct 22 13:29:56 EDT 2001


Tim Peters wrote:
>dictionary() is a constructor in 2.2, and I spent a lot of time worrying
>about what kind of arguments it should take.  I believe a flat [k,v,...]
>list would have been the most useful thing to accept; but it had to at
least
>accept a mapping object, and that's all it accepts (for now).  Everyone's
>first thought seems to be that dictionary() should accept a list of (key,
>value) tuples -- but there are few core functions that produce such a list
>(dict.items(), zip() and some cases of map() are all that pop to mind), so
I
>had a hard time picturing a good use for that (yet another way to spell
>dict.copy() is not a good use).

Since there was a stalemate on the pros and cons of overloading/confusing
the dictionary constructor ...
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 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 and without having to add
more builtin functions, etc.

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

Jim






More information about the Python-list mailing list