[Miles]
> I assume that "smallish values of n" refers to the fact that
> itertools.tee places items into every generator's internal deque,
> which islice then skips over, whereas your version places items only
> into the deque of the generator that needs it.
The pure python equivalent listed in th
On Wed, Apr 8, 2009 at 1:21 PM, pataphor wrote:
> On Wed, 08 Apr 2009 10:51:19 -0400 Neal Becker wrote:
>
>> What was wrong with this one?
>>
>> def demux(iterable, n):
>> return tuple(islice(it, i, None, n) for (i, it) in
>> enumerate(tee(iterable, n)))
>
> Nothing much, I only noticed after p
On Wed, 08 Apr 2009 10:51:19 -0400
Neal Becker wrote:
> What was wrong with this one?
>
> def demux(iterable, n):
> return tuple(islice(it, i, None, n) for (i, it) in
> enumerate(tee(iterable, n)))
Nothing much, I only noticed after posting that this one handles
infinite sequences too. For
pataphor wrote:
> On 07 Apr 2009 02:05:59 GMT
> Steven D'Aprano wrote:
>
>> The demuxer can't be an iterator, since it needs to run through the
>> entire collection.
>
> Then your demuxer obviously cannot handle infinite sequences.
>
>> def demux(it, n):
>> collectors = [[] for i in xrang
On 07 Apr 2009 02:05:59 GMT
Steven D'Aprano wrote:
> The demuxer can't be an iterator, since it needs to run through the
> entire collection.
Then your demuxer obviously cannot handle infinite sequences.
> def demux(it, n):
> collectors = [[] for i in xrange(n)]
> i = 0
> for item
On Mon, Apr 6, 2009 at 10:05 PM, Steven D'Aprano wrote:
> On Mon, 06 Apr 2009 20:05:51 -0400, Neal Becker wrote:
>
>> I'm trying to make a multiplexor and demultiplexor, using generators.
>> The multiplexor will multiplex N sequences -> 1 sequence (assume equal
>> length). The demultiplexor will d
On Mon, Apr 6, 2009 at 8:05 PM, Neal Becker wrote:
> I'm trying to make a multiplexor and demultiplexor, using generators. The
> multiplexor will multiplex N sequences -> 1 sequence (assume equal length).
> The demultiplexor will do the inverse.
>
> The demux has me stumped. The demux should ret
On Mon, 06 Apr 2009 20:05:51 -0400, Neal Becker wrote:
> I'm trying to make a multiplexor and demultiplexor, using generators.
> The multiplexor will multiplex N sequences -> 1 sequence (assume equal
> length). The demultiplexor will do the inverse.
>
> The mux seems easy enough:
>
> -
I'm trying to make a multiplexor and demultiplexor, using generators. The
multiplexor will multiplex N sequences -> 1 sequence (assume equal length).
The demultiplexor will do the inverse.
The mux seems easy enough:
---
def mux (*ranges):
iterables = [iter (r) for r i