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