Why are there no ordered dictionaries?

Tom Anderson twic at urchin.earth.li
Fri Nov 25 22:11:16 EST 2005


On Fri, 25 Nov 2005, Christoph Zwerschke wrote:

> Tom Anderson wrote:
>
>> True, but that's not exactly rocket science. I think the rules governing 
>> when your [] acts like a dict [] and when it acts like a list [] are vastly 
>> more complex than the name of one attribute.
>
> I think it's not really rocket science either to assume that an ordered 
> dictionary behaves like a dictionary if you access items by subscription 
> and like a list if you use slices (since slice indexes must evaluate to 
> integers anyway, they can only be used as indexes, not as keys).

When you put it that way, it makes a certain amount of sense - [:] is 
always about index, and [] is always about key. It's still icky, but it is 
completely unambiguous.

tom

-- 
I content myself with the Speculative part [...], I care not for the
Practick. I seldom bring any thing to use, 'tis not my way. Knowledge
is my ultimate end. -- Sir Nicholas Gimcrack



More information about the Python-list mailing list