Dictionary from list?

Andrei Kulakov sill at optonline.net
Fri Oct 19 11:50:33 EDT 2001


On Fri, 19 Oct 2001 03:42:57 GMT, Jim Correia <jim.correia at pobox.com> wrote:
> Suppose I have a list with an even number of elements in the form
> 
> [key1, value1, key2, value2, key3, value3]
> 
> If I were writing Perl I could write
> 
> my %hash = @array;
> 
> and it would do the coercion for me, and build the hash appropriately.
> 
> I'm a python newbie.  I know how to do it "by hand" with a loop, but is 
> there a built in conversion operater that will let me do something 
> simply like the perl assignment?
> 
> Jim

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.

 - Andrei

-- 
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org



More information about the Python-list mailing list