python迭代器增加元素、iterator拼接

方法肯定有好多种,目前用的觉得还不错的是下面这种

import itertools
iter1 = iter([1,2,3])
iter2 = iter([4,5,6])
iter3 = itertools.chain(iter1, iter2)

赞:
https://stackoverflow.com/questions/571850/adding-elements-to-python-generators
https://stackoverflow.com/questions/1264319/need-to-add-an-element-at-the-start-of-an-iterator-in-python

猜你喜欢

转载自blog.csdn.net/qxqxqzzz/article/details/107105188
今日推荐