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