This question already has an answer here:
- How to make a flat list out of list of lists? 39 answers
Suppose we have an iterator (an infinite one) that returns lists (or finite iterators), for example one returned by
infinite = itertools.cycle([[1,2,3]])
What is a good Python idiom to get an iterator (obviously infinite) that will return each of the elements from the first iterator, then each from the second one, etc. In the example above it would return 1,2,3,1,2,3,...
. The iterator is infinite, so itertools.chain(*infinite)
will not work.
Related
- Flattening a shallow list in python