标签:
# coding=utf8 from collections import Iterator from collections import Iterable #迭代器对象 class OwnIteror( Iterator ): def __init__(self , arrs ): self.index = 0 self.arrs = arrs def next(self): if self.index > len( self.arrs ) - 1: raise StopIteration else: self.index +=1 return self.arrs[ self.index - 1 ] #可迭代对象 class OwnIterable( Iterable ): def __init__(self , arrs ): self.arrs = arrs def __iter__(self): return OwnIteror( self.arrs ) for item in OwnIterable( [ 1,2,3,4,4,6 ] ): print item
标签:
原文地址:http://www.cnblogs.com/codefly-sun/p/5932405.html