[Python-Dev] re: for in dict (user expectation poll)

Ka-Ping Yee ping@lfw.org
Tue, 6 Feb 2001 01:11:31 -0800 (PST)


On Mon, 5 Feb 2001, Fredrik Lundh wrote:
> yeah, don't forget unpacking assignments:
> 
>     assert len(dict) == 3
>     { k1:v1, k2:v2, k3:v3 } = dict

I think this is a total non-issue for the following reasons:

    1.  Recall the original philosophy behind the list/tuple split.
        Lists and dicts are usually variable-length homogeneous
        structures, and therefore it makes sense for them to be
        mutable.  Tuples are usually fixed-length heterogeneous
        structures, and so it makes sense for them to be immutable
        and unpackable.

    2.  In all the Python programs i've ever seen or written, i've
        never known or expected a dictionary to have a particular
        fixed length.

    3.  Since the items come back in random order, there's no point
        in binding individual ones to individual variables.  It's
        only ever useful to iterate over the key/value pairs.

In short, i can't see how anyone would ever want to do this.

(Sorry for being the straight man, if you were in fact joking...)


-- ?!ng

"There's no point in being grown up if you can't be childish sometimes."
    -- Dr. Who