f | from itertools import tee, zip_longest | f | from itertools import tee, zip_longest |
| | | |
t | def seesaw(seq): | t | def seesaw(sequence): |
| (seq0, seq1) = tee(seq) | | (ch1, ch2) = tee(sequence) |
| seq0 = (x for x in seq0 if x % 2 == 0) | | |
| seq1 = (x for x in seq1 if x % 2 == 1) | | tmp1 = (n for n in ch1 if n % 2 == 0) |
| | | tmp2 = (n for n in ch2 if n % 2 == 1) |
| for (a, b) in zip_longest(seq0, seq1, fillvalue=None): | | for (x, y) in zip_longest(tmp1, tmp2, fillvalue=None): |
| if a is not None: | | if x != None: |
| yield a | | yield x |
| if b is not None: | | if y != None: |
| yield b | | yield y |