Dictionary from list?

Martien Verbruggen mgjv at tradingpost.com.au
Fri Oct 19 21:28:55 EDT 2001


On Fri, 19 Oct 2001 11:03:52 -0700,
	Erik Max Francis <max at alcyone.com> wrote:
> Andrei Kulakov wrote:
> 
>> You know, this sort of thing comes up often - X is a built-in feature
>> in
>> perl, why do I have to do it manually in python? I think this is a
>> justified design decision - there's simply too many built-in things
>> perl
>> does. You can't remember all of them and if you look at someone else's
>> perl program you have to scratch your head a lot. Python is small,
>> lean
>> and clean, and that's one of the best things about it.
> 
> In particular, what this is really revealing is that a Perl associative
> array is really represented as a list, with each successive pair
> representing a key and a value.  (When writing list and associative
> array literals, you see the same thing.)

Euhmmm... No, I don't agree. 

What this reveals is that in Perl lists, arrays and hashes
are totally different things, but they can be assigned to each other
(with some restrictions). A list is not a Perl data type, it's something
that exists internally in Perl and gets produced by subroutine calls,
and certain operations. Even that thing with the parentheses and
the commas isn't really a list; it produces a list at runtime.

To say that Perl hashes are implemented as lists really misses the point
of what a hash is and what a list is. If hashes were lists, then they
wouldn't be any faster than an array, and their existence would be
totally superfluous. The last time I read the bits of perl's sources
that pertain to hashes, they were still implemented as a hash :)

> This goes back to Perl's weakly-typed approach to everything.  Since
> Python is not weakly typed, emulating this behavior is not only not
> convenient, but is not even advisable.

I don't see why this is relevant. Python is strongly typed, yes, but
that doesn't mean you _could_ in no circumstance make tuples or lists
and hashes assignment-compatible, even if only in one direction. C is
strongly typed, but it allows many assigments with automatic conversions
between variables with differing (but assignment-compatible!) types.

That Perl is weakly typed is beside the point. That Perl has
well-defined automatic conversion behaviour between (almost) all of its
internal types is closer to the point.

That during the design of python some decisions were made to have strict
boundaries between these things, and not allow assignments to work from
one type to another is probably more the issue.

Martien
-- 
                                | 
Martien Verbruggen              | Begin at the beginning and go on till
                                | you come to the end; then stop.
                                | 



More information about the Python-list mailing list