As the title asks. Python has a lot of special methods, __add__
, __len__
, __contains__
et c. Why is there no __max__
method that is called when doing max? Example code:
class A:
def __max__():
return 5
a = A()
max(a)
It seems like range()
and other constructs could benefit from this. Am I missing some other effective way to do max?¨
Addendum 1:
As a trivial example, max(range(1000000000))
takes a long time to run.
No comments:
Post a Comment