I dont understand how changed type from list to dict on constructor in main class if i got to subclass another type - dict.
What is magic is this?
class Adder:
def __init__(self, data = [ ]):
self.data = data
def __add__(self, other):
return "Not Implemented"
class DictAdder(Adder):
def __add__(self, y):
z = {}
for k in self.data.keys(): z[k] = self.data[k]
for k in y.keys(): z[k] = y[k]
return z
y = DictAdder({1:'a', 2:'b'})
l = y + { 3: 'c', 4: 'd'}
print(l)
and answer:
{1: 'a', 2: 'b', 3: 'c', 4: 'd'}
Pycharm show what self.data.keys() dont have attribute keys() and this must be try, because data is a list, but this is work