Consider the class AB
below that is to be used as a simple customized list of A
objects for lookup operations.
Can this code be improved to avoid instantiating AB
with an empty list []
(i.e., perhaps modify __add__
in some way)?
class A():
def __init__(self, arg):
self.arg = arg
class AB():
def __init__(self, list):
self.list = list
def __add__(self, other):
return AB(self.list + [other])
ab = AB([])
ab += A(1)
ab += A(2)