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