Python equivalent to java.util.SortedSet?

前端 未结 7 1891
灰色年华
灰色年华 2021-02-05 06:59

Does anybody know if Python has an equivalent to Java\'s SortedSet interface?

Heres what I\'m looking for: lets say I have an object of type foo, and I know

7条回答
  •  耶瑟儿~
    2021-02-05 07:22

    Similar to blist.sortedlist, the sortedcontainers module provides a sorted list, sorted set, and sorted dict data type. It uses a modified B-tree in the underlying implementation and is faster than blist in most cases.

    The sortedcontainers module is pure-Python so installation is easy:

    pip install sortedcontainers
    

    Then for example:

    from sortedcontainers import SortedList, SortedDict, SortedSet
    help(SortedList)
    

    The sortedcontainers module has 100% coverage testing and hours of stress. There's a pretty comprehensive performance comparison that lists most of the options you'd consider for this.

提交回复
热议问题