def __iter__(self): return MyBoxIterator(self.items) # Implement a container class MyBox in the mybox.py file that stores and operates with the objects of the class developed by you in the task 8 # of the seminar tasks 1 (in the file myclass.py). Your container class needs to implement the following methods: # - constructor method that initializes the container with some objects (more than one); # - len() method that outputs the number of objects in the container ; # - add(obj) method that adds a new object in the container; # - remove(obj) method that removes the specified object from the container; # - contains(obj) method that checks whether the specified object is in the container; # - iterator() method that returns an iterator over the objects in the container;
def __iter__(self): return MyBoxIterator(self.vrbl)
def __iter__(self, object): return MyBoxIterator(self.plov)
def iterator(self): return MyBoxIterator(self.box)
def __iter__(self): return MyBoxIterator(self._theItems)
def __iter__(self): return MyBoxIterator(self.points)
def iterator(self): return MyBoxIterator(self.container)
from mybox import Mybox m = Mybox(['red', 'blue']) m.add("red") m.add("grey") m.add("black") print(len(m)) m.remove() print(len(m)) print('pink' in m) from myboxiterator import MyBoxIterator mbi = MyBoxIterator() next(mbi) next(mbi) for n in mbi: print(n) if n: break
from myboxiterator import MyBoxIterator class MyBox(): def __init__(self): self.points = list() def __len__(self): return len(self.points) def add(self, point): self.points.append(point) def remove(self, point): assert point in self.points ind = self.points.index(point) return self.points.pop(ind) def __contains__(self, point): return point in self.points def __iter__(self): return MyBoxIterator(self.points)
def __iter__(self): return MyBoxIterator(self.data)