t | import itertools | t | import itertools |
| | | |
| def seesaw(sequence): | | def seesaw(sequence): |
| even_iter, odd_iter = itertools.tee(sequence) | | even_iter, odd_iter = itertools.tee(sequence) |
| even_iter = filter(lambda x: x % 2 == 0, even_iter) | | even_iter = filter(lambda x: x % 2 == 0, even_iter) |
| odd_iter = filter(lambda x: x % 2 != 0, odd_iter) | | odd_iter = filter(lambda x: x % 2 != 0, odd_iter) |
| for even, odd in itertools.zip_longest(even_iter, odd_iter): | | for even, odd in itertools.zip_longest(even_iter, odd_iter): |
| if even is not None: | | if even is not None: |
| yield even | | yield even |
| if odd is not None: | | if odd is not None: |
| yield odd | | yield odd |