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

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Wed Mar 9 03:40:11 CET 2005


Greg Ward wrote:

I'll attach another approach to the same problem, an ordered dictionary object. I believe the semantics of adding/readding/deleting keys is the same as java.util.LinkedHashMap -- certainly it seems the most sensible and easy-to-implement semantics.

That's essentially the same approach I used - I didn't get around to properly implementing a doubly-linked list between the keys - I just maintained a list with the correct order. If I'm going to write a Cookbook recipe though I should probably do it properly ...

Personally, I think it would be quite nice if all python dictionaries had these semantics - it would be nice to be able to say that items will be returned in the order they're inserted - but I wouldn't want to incur the additional cost in such a fundamental data structure.

One thing I did notice - dict.repr and dict.str don't produce strings in the iteration order of subclasses - they always use the arbitrary dict iteration order. Is this intentional?

Tim Delaney



More information about the Python-Dev mailing list