def __iter__(self): i = 0 try: while True: v = self[i] yield v i += 1 except IndexError: return
def __contains__(self, value): for v in self: if v is value or v == value: return True return False
def __reversed__(self): for i in reversed(range(len(self))): yield self[i]
def index(self, value, start=0, stop=None): '''S.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended. ''' if start is not None and start < 0: start = max(len(self) + start, 0) if stop is not None and stop < 0: stop += len(self)
i = start while stop is None or i < stop: try: v = self[i] if v is value or v == value: return i except IndexError: break i += 1 raise ValueError
def count(self, value): 'S.count(value) -> integer -- return number of occurrences of value' return sum(1 for v in self if v is value or v == value)
class Reversible(Iterable):
__slots__ = ()
@abstractmethod def __reversed__(self): while False: yield None
@classmethod def __subclasshook__(cls, C): if cls is Reversible: return _check_methods(C, "__reversed__", "__iter__") return NotImplemented
class Collection(Sized, Iterable, Container):
__slots__ = ()
@classmethod def __subclasshook__(cls, C): if cls is Collection: return _check_methods(C, "__len__", "__iter__", "__contains__") return NotImplemented
class Sized(metaclass=ABCMeta):
__slots__ = ()
@abstractmethod def __len__(self): return 0
@classmethod def __subclasshook__(cls, C): if cls is Sized: return _check_methods(C, "__len__") return NotImplemented
class Iterable(metaclass=ABCMeta):
__slots__ = ()
@abstractmethod def __iter__(self): while False: yield None
@classmethod def __subclasshook__(cls, C): if cls is Iterable: return _check_methods(C, "__iter__") return NotImplemented
def __contains__(self, item): if item in self.staffs: return True else: return False
staffs = ["bobby1", "imooc", "bobby2", "bobby3"] group = Group(company_name="imooc", group_name="user", staffs=staffs) reversed(group) for user in group: print(user)