As this popular question explains, range objects in Python 3 are clever enough to be able to test efficiently for membership:
In [1]: 1000000000000000 in range(1000000000000001)
Out[1]: True # answer returned very quickly
However, the same is not true for the evaluation of a range's maximum and minimum values with max and min, which seems to iterate over the entire sequence to find these values:
In [2]: max(range(1000000000000001)) # don't do this
...
It would be trivial to implement these functions efficiently for range objects, so why hasn't it been done? Is there some implementation detail or edge case I am missing?
maxknow that the sequence is sorted?maxdoes not defer to dunder methods, it is a dumb O(n) algorithm that simply iterates over the sequence as given.inandlendefer to dunder methods that can be overridden,maxandmindo not (and I suppose making them so would be an implementation change too far for this use-case).