Dictionary from list?

Steve Holden sholden at holdenweb.com
Tue Oct 23 06:58:31 EDT 2001


"Tim Peters" <tim.one at home.com> wrote ...
> [Steve Holden]
> > 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?
>
> There's already a dictionary() constructor in 2.2, and that's not going to
> change (it would be too odd if every scalar and container builtin type had
a
> builtin constructor except for dicts).  One question is what it should do;
> all it can do in 2.2b1 is basically silly, amounting to yet another way to
> spell "shallow-copy the argument".
>
Well, I certainly agree that

    TypeError: argument must be of a mapping type

isn't impressive. If it has to be a mapping already then making a dictionary
out of it doesn't really help a lot (though I suppose it might speed up
access for mappings with complex implementations behind them).

> Sticking a toDict() method on lists isn't appealing regardless because
> "iterable object" is the natural decomposition in 2.2 (for example, a
tuple
> of two-element lists is just as good of an input argument as a list of
> two-element tuples, ditto a generator producing a sequence of address-book
> objects that supply an iterator over their name and address fields, and so
> on -- "a list" just isn't special here).
>
Sorry, must have been "Not Thinking in Java" for a second there. Given the
rich variety of choices which *could* be made here, I don't see an argument
that any *specific* choice would be less silly than any other. Certainly not
really any argument for Perl's particular coercion.

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








More information about the Python-list mailing list