class sorted_list(object):
def __init__(self,elements): self.elements=sorted(elements) def __iter__(self): self.position=-1
return self
def __next__(self): if self.position == len(self.elements)-1:
raise StopIteration self.position+=1
return self.elements[self.position]
namelist=['a','d','c']
sorted_namelist=sorted_list(namelist)#提示这一行 超过最大迭代深度限制for name in sorted_namelist:
print(name)
1 回答
犯罪嫌疑人X
TA贡献2080条经验 获得超4个赞
缩进问题
def __next__(self): if self.position == len(self.elements)-1: raise StopIteration self.position+=1
要改成
def __next__(self): if self.position == len(self.elements)-1: raise StopIteration self.position+=1
添加回答
举报
0/150
提交
取消