f | from itertools import zip_longest, tee | f | from itertools import zip_longest, tee |
| | | |
t | def seesaw(sequence): | t | def seesaw(seq): |
| (even, not_even) = tee(sequence, 2) | | (hehe1, hehe2) = tee(seq, 2) |
| even = filter(lambda x: x % 2 == 0, even) | | seq1 = filter(lambda x: x % 2 == 0, hehe1) |
| not_even = filter(lambda x: x % 2 == 1, not_even) | | seq2 = filter(lambda x: x % 2 != 0, hehe2) |
| for (e, n) in zip_longest(even, not_even): | | for (i, j) in zip_longest(seq1, seq2): |
| if e is not None: | | if i != None: |
| yield e | | yield i |
| if n is not None: | | if j != None: |
| yield n | | yield j |