Пример #1
0
    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;
Пример #2
0
 def __iter__(self):
     return MyBoxIterator(self.vrbl)
Пример #3
0
    	def __iter__(self, object):
		return MyBoxIterator(self.plov)
Пример #4
0
	def iterator(self):
		return MyBoxIterator(self.box)
Пример #5
0
 def __iter__(self):
     return MyBoxIterator(self._theItems)
Пример #6
0
 def __iter__(self):
     return MyBoxIterator(self.points)
Пример #7
0
 def iterator(self):
     return MyBoxIterator(self.container)
Пример #8
0
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
Пример #9
0
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)
Пример #10
0
 def __iter__(self):
     return MyBoxIterator(self.data)