逐个提取值
从内置的 iter()
开始,通过迭代获取迭代器,并使用 next()
逐个获取元素,直到提示 StopIteration
表示结束:
s = {1, 2} # or list or generator or even iterator
i = iter(s) # get iterator
a = next(i) # a = 1
b = next(i) # b = 2
c = next(i) # raises StopIteration
从内置的 iter()
开始,通过迭代获取迭代器,并使用 next()
逐个获取元素,直到提示 StopIteration
表示结束:
s = {1, 2} # or list or generator or even iterator
i = iter(s) # get iterator
a = next(i) # a = 1
b = next(i) # b = 2
c = next(i) # raises StopIteration