Switch all xrange -> range for Python 3 compatibility.

    $ 2to3.py -p -fxrange .

I haven't measured performance implications of this. Would you like me to do so?

I think some of these cases could switch to use enumerate() for better perf and style on both Python versions, but that sounds like a separate effort.