N
Neal Becker
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 in ranges]
while (True):
for i in (iterables):
yield i.next()
def test_mux ():
a = xrange (10)
b = xrange (10,20)
return mux (a, b)
x = test_mux()
print [e for e in x]
------------------------
The demux has me stumped. The demux should return a tuple of N generators.
The signature should be:
def demux (sequence, N):
Not sure about this one.
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 in ranges]
while (True):
for i in (iterables):
yield i.next()
def test_mux ():
a = xrange (10)
b = xrange (10,20)
return mux (a, b)
x = test_mux()
print [e for e in x]
------------------------
The demux has me stumped. The demux should return a tuple of N generators.
The signature should be:
def demux (sequence, N):
Not sure about this one.