I know you can do this with an OrderedDict
. I don’t think it’s possible without creating a temporary for the indexing because the internal indexing of a SortedDict
is much more difficult. This is because OrderedDict
stores everything in arrays while SortedDict
stores everything in a BalancedTree
. So you have to really step through the tree to find out what the next value is, which is what collecting the iterator does.
Maybe it could be better for you to sort it yourself and use an OrderedDict
for this reason? Or maybe find a way to save what the indexes to the BalancedTree
mean, and mutate this when a value is added?