That was an exciting ride! First an if statement that was longer than one would want, then he was splitting things off into small bits and a loop to make it look neat and dynamic, and then it exploded into bullshit and stopped looking like Python altogether.
Guess it happens.