Does python have a sorted list?

list, python, sorting

Solution

The standard Python list is not sorted in any form. The standard heapq module can be used to append in O(log n) to an existing list and remove the smallest one in O(log n), but isn't a sorted list in your definition.

There are various implementations of balanced trees for Python that meet your requirements, e.g. rbtree, RBTree, or pyavl.

Problem

By which I mean a structure with: - O(log n) complexity for `x.push()` operations - O(log n) complexity to find an element - O(n) complexity to compute `list(x)` which will be sorted I also had a related question about performance of `list(...).insert(...)` which is now here.

Original source

Related problems