Question: language python. # 10.4.3.b extend List's built-in ordering relations with an ownership check class MyList(list): def __init__(self, 1, owner ): super(). __init_(i) self.owner = Owner


language python.
# 10.4.3.b extend List's built-in ordering relations with an ownership check class MyList(list): def __init__(self, 1, owner ): super(). __init_(i) self.owner = Owner # def __eq_(self, other): return isinstance(other, MyList) and super(). _e9__(other) and self.owner == other.owner def __ne_(self, other): return not isinstance (other, MyList) or super(). __ne__(other) or self.owner != other.owner def __str_(self): return str((super(). __str_0, self.owner)) mylist_123_phil = MyList([1, 2, 3], 'Phil') mylist_456_phil = MyList([4, 5, 6], 'Phil') mylist_123_bob MyList([1, 2, 3], 'Bob') for list_a in [mylist_123_phil, mylist_456_phil, mylist_123_bob]: for list_b in (mylist_123_phil, mylist_456_phil, mylist_123_bob]: print( f'{list_a} == {list_b} is {list_a == list_b}') print( f'{list_a} != {list_b} is (list_a != list_b}') print() Exercise: (2 points) In the following code cell, create and demonstrate the use of a _repr_method for MyList. This method should be defined so that eval(repr(m)) == m for any instance m of MyList. # 10.4.3.b extend List's built-in ordering relations with an ownership check class MyList(list): def __init__(self, 1, owner ): super(). __init_(i) self.owner = Owner # def __eq_(self, other): return isinstance(other, MyList) and super(). _e9__(other) and self.owner == other.owner def __ne_(self, other): return not isinstance (other, MyList) or super(). __ne__(other) or self.owner != other.owner def __str_(self): return str((super(). __str_0, self.owner)) mylist_123_phil = MyList([1, 2, 3], 'Phil') mylist_456_phil = MyList([4, 5, 6], 'Phil') mylist_123_bob MyList([1, 2, 3], 'Bob') for list_a in [mylist_123_phil, mylist_456_phil, mylist_123_bob]: for list_b in (mylist_123_phil, mylist_456_phil, mylist_123_bob]: print( f'{list_a} == {list_b} is {list_a == list_b}') print( f'{list_a} != {list_b} is (list_a != list_b}') print() Exercise: (2 points) In the following code cell, create and demonstrate the use of a _repr_method for MyList. This method should be defined so that eval(repr(m)) == m for any instance m of MyList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
