Dictionary from list?

Steve Holden sholden at holdenweb.com
Tue Oct 23 01:17:31 CEST 2001


<James_Althoff at i2.com> wrote ...
>
> 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 ;-)
>
Erm, wouldn't it make more sense (since there isn't a dictionary to start
with) to implement a "toDict()" method of lists rather than a dictionary
constructor?

Just a thought.

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list