Question about consistency in python language

James Stroud jstroud at mbi.ucla.edu
Thu Sep 8 19:54:45 EDT 2005


This is the difference between mutable and immutable types. In this sense it 
is consistent.

If you want to do the former in one shot:

   h = dict(l)

Also, you shouldn't use "1", I mean "l", as a variable name. It gets confusing 
because "l", I mean "1", looks a lot like "1", I mean "l".

James

On Thursday 08 September 2005 16:03, lechequier at gmail.com wrote:
> Let's say I define a list of pairs as follows:
> >>l = [('d', 3), ('a', 2), ('b', 1)]
>
> Can anyone explain why this does not work?
>
> >>h = {}.update(l)
>
> and instead I have to go:
> >>h = {}
> >>h.update(l)
>
> to initialize a dictionary with the given list of pairs?
>
> when an analagous operation on strings works fine:
> >>s = "".join(["d","o","g"])
>
> Seems inconsistent.
>
> thanks,
> Scott

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list