Got this exercise in python exam. Trying to return a deep copy of this list:
l = list() l = [0,1,2] l1 = l l[0] = 1
l1 must contain [0,1,2]
not [1,1,2]
The exercise indicated for its implementation using the metaclass.
class deep(type): def __new__(meta, classname, bases, classDict): return type.__new__(meta, classname, bases, classDict) def __init__(cls, name, bases, dct): super(deep, cls).__init__(name, bases, dct) def __call__(cls, *args, **kwds): return type.__call__(cls, *args, **kwds) class list(metaclass=deep): def __init__(self): pass
From what I know, '='
in python is an operator, not an operator, and cannot be overridden. Any idea on how to return a deep copy on appointment? We tried quite a lot, but without success.