f | from collections import deque | f | from collections import deque |
| | | |
| def seesaw(sequence): | | def seesaw(sequence): |
n | even_queue = deque() | n | evens = deque() |
| odd_queue = deque() | | odds = deque() |
| for item in sequence: | | for number in sequence: |
| if item % 2 == 0: | | if number % 2 == 0: |
| even_queue.append(item) | | evens.append(number) |
| else: | | else: |
t | odd_queue.append(item) | t | odds.append(number) |
| while even_queue or odd_queue: | | while evens or odds: |
| if even_queue: | | if evens: |
| yield even_queue.popleft() | | yield evens.popleft() |
| if odd_queue: | | if odds: |
| yield odd_queue.popleft() | | yield odds.popleft() |