How to extend/concatenate two iterators in Python [duplicate] How to extend/concatenate two iterators in Python [duplicate] python-3.x python-3.x

How to extend/concatenate two iterators in Python [duplicate]


Use itertools.chain:

from itertools import chainy_iter = chain(l1, l2)

It yields all the items from l1 and then all the items from l2. Effectively concatenating the sequence of yielded items. In the process it consumes both.


you can use the chain() function provided by the itertools

itertools.chain()