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.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to