26

Is there a built-in sorted dictionary implementation in Python 2.6, or are hashtables the only kind?

Clarifications:

  • I'm asking about sorted dictionarys, not ordered dictionaries!
4

4 に答える 4

11

I think the answer here is no.

There is a Treemap but it isn't in the python standard library.

http://pypi.python.org/pypi/treemap/

I think to those who don't like my answer, may think it's wrong due to a recent update. Please note this is for Python 2.6, not 2.7 or Python 3

Please add the correct answer if you still think it's wrong, or unhelpful, or at least give a reason why you think it's a bad answer.

于 2011-07-30T22:31:25.943 に答える
6

Built-in no, as a third party package you can check blist , here is the doc for sorteddict.

于 2011-07-30T23:23:32.670 に答える
2

I wrote a Python version of the Java TreeMap/TreeSet.

Source code and documentation can be accessed in this repo

You can install with pip install pytreemap. Tested for Python >=3.5

于 2020-06-24T19:28:39.403 に答える
1

If by build-in you mean provided with a standard python install, the answer is no.

If you mean at the same level of implementation as Python's build-in dict then have a look at my C implementation of sorteddict and ordereddict: http://anthon.home.xs4all.nl/Python/ordereddict/

于 2012-06-18T09:19:36.397 に答える