sortedcontainers

Get minimum of SortedKeyList with a condition on an object attribute

Get minimum of SortedKeyList with a condition on an object attribute Question: I have a SortedKeyList of objects sorted by timestamp, the objects also have another attribute, the ID. I was trying to get the earliest element of the list based on the ID. This is a code example: import numpy as np import sortedcontainers …

Total answers: 2

How to use binary search on an existing SortedList with a key function?

How to use binary search on an existing SortedList with a key function? Question: I would like to use binary search on a SortedList with a key function, e.g. similarly to bisect_right() in the bisect module. However, SortedList.bisect_right() only supports searching by value. How to make it work with a key function? Asked By: Eugene …

Total answers: 2

Time complexity iterating over items in a SortedDict?

Time complexity iterating over items in a SortedDict? Question: from sortedcontainers import SortedDict d = SortedDict(b=20, d=30, c=10, e=50, a=40) # What is the time complexity of the following code? for k, v in d.items(): print(k, v) I think the time complexity should be nlog(n) as getting an entry from a sorted dictionary costs log(n), …

Total answers: 3