对 Python 的 列表/字典/集合 进行排序:sorted_containers

jopen 9年前

sorted_containers 对 Python 的 列表/字典/集合 进行排序. 支持 Python 2.6, 2.7(PyPY), 3.2(PyPy 3), 3.3 和 3.4。

>>> sl = sortedcontainers.SortedList(xrange(10000000))  >>> 1234567 in sl  True  >>> sl[7654321]  7654321  >>> sl.add(1234567)  >>> sl.count(1234567)  2  >>> sl *= 3  >>> len(sl)  30000003

特性

  • 纯Python
  • 完整的文档
  • Benchmark comparison (alternatives, runtimes, load-factors)
  • 100% test coverage
  • Hours of stress testing
  • Performance matters (often faster than C implementations)
  • Compatible API (nearly identical to popular blist and rbtree modules)
  • Feature-rich (e.g. get the five largest keys in a sorted dict: d.iloc[-5:])
  • Pragmatic design (e.g. SortedSet is a Python set with a SortedList index)
  • Developed on Python 2.7
  • Tested on CPython 2.6, 2.7, 3.2, 3.3, 3.4 and PyPy 2.2+, PyPy3 2.3.1+

项目主页:http://www.open-open.com/lib/view/home/1414739114153