Refactor: python: Unindent several complicated loops.
Some of these are indented and nested pretty far. Where possible, just
invert the conditional inside the loop and have it continue if met.
This allows un-indenting all the code below it. No real code changes
otherwise.