[Python-3000] ordered dict for p3k collections? (original) (raw)
Georg Brandl g.brandl at gmx.net
Sat Sep 15 18:48:18 CEST 2007
- Previous message: [Python-3000] ordered dict for p3k collections?
- Next message: [Python-3000] ordered dict for p3k collections?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Arvind Singh schrieb:
I hope that Python gets a sorteddict and a sortedset.
It doesn't make sense for Python to have sorteddict or sortedset. You see, dict can have keys which cannot be ordered (keys can be heterogeneous, in which case Py3K may raise TypeError; ordering doesn't make sense for the objects used as keys) and same goes for set elements. Sorting makes sense only as a run-time operation, in which case, the programmer should be prepared to handle appropriate exceptions. Btw, would you like a dict or set for which you have to handle exceptions at every insertion?
In the cases where you have to do that, you shouldn't be using a sorted dict.
But why not better look at those other 95% of cases where the values are uniformly typed and perfectly sortable?
Georg
-- Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.
- Previous message: [Python-3000] ordered dict for p3k collections?
- Next message: [Python-3000] ordered dict for p3k collections?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]