f | def seesaw(sequence): | f | def seesaw(sequence): |
n | even = [] | n | evens = [] |
| odd = [] | | odds = [] |
| for i in sequence: | | for number in sequence: |
| if i % 2 == 0: | | if number % 2 == 0: |
| even.append(i) | | evens.append(number) |
| else: | | else: |
t | odd.append(i) | t | odds.append(number) |
| even_index, odd_index = (0, 0) | | i, j = (0, 0) |
| while even_index < len(even) or odd_index < len(odd): | | while i < len(evens) or j < len(odds): |
| if even_index < len(even): | | if i < len(evens): |
| yield even[even_index] | | yield evens[i] |
| even_index += 1 | | |
| if odd_index < len(odd): | | |
| yield odd[odd_index] | | |
| odd_index += 1 | | i += 1 |
| | | if j < len(odds): |
| | | yield odds[j] |
| | | j += 1 |