[Python-Dev] LinkedHashSet/LinkedHashMap equivalents (original) (raw)

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Thu Mar 10 05:55:45 CET 2005


Jeff Bauer wrote:

I'm not specifically lobbying for its inclusion in stdlib, but I often find an ordered dict useful when I want both ordered and random access, e.g. situations:

- database table fields/attributes - drop down field selectors

Yep - these are also cases that are familiar to me - it's the type of thing you don't think about until you actually need it.

In both cases, I could get by with other techniques, but I would use stdlib ordered dicts if they were available. I also prefer the term "ordered dict" to LinkedHashXXX.

You may notice the subject is LinkedHashXXX equivalents ;) There is no way I would ever propose adding them with those names.

OTOH, "ordered set" and "ordered dict" implies different things to different people - usually "sorted" rather than "the order things were put in". Perhaps "temporally-ordered" ;)

BTW, just to clarify the semantics:

Set: Items are iterated over in the order that they are added. Adding an item that compares equal to one that is already in the set does not replace the item already in the set, and does not change the iteration order. Removing an item, then re-adding it moves the item to the end of the iteration order.

Dict: Keys are iterated over in the order that they are added. Setting a value using a key that compares equal to one already in the dict replaces the value, but not the key, and does not change the iteration order. Removing a key (and value) then re-adding it moves the key to the end of the iteration order.

Tim Delaney



More information about the Python-Dev mailing list