multirember&co
Anton Vredegoor
anton.vredegoor at gmail.com
Fri Apr 20 18:02:10 CEST 2007
Anton Vredegoor wrote:
> from collections import deque
>
> def xsplitter(seq, pred):
> Q = deque(),deque()
> it = iter(seq)
> def gen(p):
> for x in it:
> if pred(x) == p:
> Q[p].append(x)
> while Q[p]: yield Q[p].popleft()
> else:
> Q[~p].append(x)
> for x in gen(p): yield x
> while Q[p]: yield Q[p].popleft()
> return gen(1),gen(0)
Do we even need the line
> for x in gen(p): yield x
??!!
It seems to work the same without it.
from collections import deque
def xsplitter(seq, pred):
Q = deque(),deque()
it = iter(seq)
def gen(p):
for x in it:
if pred(x) == p:
Q[p].append(x)
while Q[p]: yield Q[p].popleft()
else:
Q[~p].append(x)
while Q[p]: yield Q[p].popleft()
return gen(1),gen(0)
What's up here? Was it a fata morgana? Am I overlooking something?
A.
More information about the Python-list
mailing list