[Python-Dev] LinkedHashSet/LinkedHashMap equivalents

"Martin v. Löwis" martin at v.loewis.de
Wed Mar 9 23:31:45 CET 2005


Thomas Heller wrote:
> I cannot understand why people are against adding it to stdlib (after
> the name, the implementation, and the exact place have been decided).
> It's certainly a useful data type, isn't it?

It depends on the precise semantics. You often want a dictionary where
the keys come out in some order - but that is rarely the order in which
they were added to the dictionary. Most frequently, you want the keys
sorted, according to some criteria. If not that, I would assume that you
typically have the order of keys determined before even filling the
dictionary, in which case you can do

for k in keys_in_preferred_order:
     v = hashtable[k]
     process(k,v)

I remember having needed that once in the past 15 years (in Smalltalk
at the time), so I wrote an OrderedDictionary for Smalltalk/V (which
didn't have it). It took me an hour or so.

I don't recall what precisely it was that I needed it for, and I cannot
think of any use case for the data type right now.

So I'm -0 on adding the data type: I have a vague feeling it is needed,
but rarely, and I don't know precisely what for.

Regards,
Martin


More information about the Python-Dev mailing list