Efficient Python solution with generator
We only need to check every other element for violating the problem statement invariant. If that happens, we can use generator to find matching pair to swap and
We only need to check every other element for violating the problem statement invariant. If that happens, we can use generator to find matching pair to swap and to also pick up where we left off on next mismatch.\n\n```\ndef sortArrayByParityII(self, A: List[int]) -> List[int]:\n\t\n        def gen_odd():\n            for j in range(1, len(A), 2):\n                if not A[j] % 2: yield j\n\n        odd = gen_odd()\n        for i in range(0,len(A),2):\n            if A[i] % 2:\n                j = next(odd)\n                A[i], A[j] = A[j], A[i]\n\n        return A\n```
[]