How to extend/concatenate two iterators in Python
you can use the chain() function provided by the itertools
itertools.chain()
Use itertools.chain
:
from itertools import chain
y_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.