逐個提取值
從內建的 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