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 how to compare two objects of type foo
to see whether foo1
is "greater than" or "less than" foo2
. I want a way of storing many objects of type foo
in a list L
, so that whenever I traverse the list L
, I get the objects in order, according to the comparison method I define.
I guess I can use a dictionary or a list and sort()
it every time I modify it, but is this the best way?
Take a look at BTrees. It look like you need one of them. As far as I understood you need structure that will support relatively cheap insertion of element into storage structure and cheap sorting operation (or even lack of it). BTrees offers that.
I've experience with ZODB.BTrees, and they scale to thousands and millions of elements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With