n | from itertools import tee | n | |
| from itertools import zip_longest | | from itertools import tee, zip_longest |
| | | |
t | def seesaw(seq): | t | def seesaw(sequence): |
| (seq_it0, seq_it1) = tee(seq) | | (a, b) = tee(sequence) |
| it0 = filter(lambda x: x % 2 == 0, seq_it0) | | a = filter(lambda x: x % 2 == 0, a) |
| it1 = filter(lambda x: x % 2 == 1, seq_it1) | | b = filter(lambda x: x % 2 == 1, b) |
| for (i, j) in zip_longest(it0, it1): | | for (i, j) in zip_longest(a, b): |
| if i != None: | | if i != None: |
| yield i | | yield i |
| if j != None: | | if j != None: |
| yield j | | yield j |