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