Steven D'Aprano writes:
> Suppose I have an iterator that yields tuples of N items (a, b, ... n).
>
> I want to split this into N independent iterators:
>
> iter1 -> a, a2, a3, ...
> iter2 -> b, b2, b3, ...
> ...
> iterN -> n, n2, n3, ...
>
> The iterator may be infinite, or at least too big to c
Steven D'Aprano writes:
> def split(iterable, n):
> iterators = []
> for i, iterator in enumerate(itertools.tee(iterable, n)):
> f = lambda it, i=i: (t[i] for t in it)
> iterators.append(f(iterator))
> return tuple(iterators)
>
> Is this the right approach, or have I mi
Steven D'Aprano wrote:
> Suppose I have an iterator that yields tuples of N items (a, b, ... n).
>
> I want to split this into N independent iterators:
>
> iter1 -> a, a2, a3, ...
> iter2 -> b, b2, b3, ...
> ...
> iterN -> n, n2, n3, ...
>
> The iterator may be infinite, or at least too big to
On Nov 6, 1:52 am, Steven D'Aprano wrote:
> I tried changing the t[i] to use operator.itergetter instead, but no
> luck. Finally I got this:
>
> def split(iterable, n):
> iterators = []
> for i, iterator in enumerate(itertools.tee(iterable, n)):
> f = lambda it, i=i: (t[i] for t in
On Nov 6, 2:52 am, Steven D'Aprano wrote:
> My first attempt was this:
>
> def split(iterable, n):
> iterators = []
> for i, iterator in enumerate(itertools.tee(iterable, n)):
> iterators.append((t[i] for t in iterator))
> return tuple(iterators)
>
> But it doesn't work, as all
Suppose I have an iterator that yields tuples of N items (a, b, ... n).
I want to split this into N independent iterators:
iter1 -> a, a2, a3, ...
iter2 -> b, b2, b3, ...
...
iterN -> n, n2, n3, ...
The iterator may be infinite, or at least too big to collect in a list.
My first attempt was thi