One rabbit hole I’ve been exploring of late, and one knows this has been discussed of long last, is a class without an __init__()
method.
>>> class SortedList(list):
def append(self, value):
super().append(value)
self.sort()
>>> a = SortedList([4,3,6,54,7,2,8,1,9,7,8,5,6,3,4,5,6,1,2])
>>> a.append(19)
>>> a
[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 19, 54]
>>> isinstance(a, SortedList)
True
>>> isinstance(a, list)
True
>>>
The only thing missing is a sorted list upon instantiation. Once we append a dummy (or real) value the list is sorted. We can remove the dummy value if needs be.
>>> b = SortedList([14,23,36,54,47,52,68,71,89,97,18,25,36,43,54,65,76,81,92])
>>> b.append(19)
>>> b
[14, 18, 19, 23, 25, 36, 36, 43, 47, 52, 54, 54, 65, 68, 71, 76, 81, 89, 92, 97]
>>> a
[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 8, 8, 9, 19, 54]
>>>
We can still have multiple instances of a class without initializing each instance, it would appear. This is worth exploring as it looks to be a vector by which we can deliver to our objects behavior that is not found in the Standard Library.