The main changes are importing the new range function and using that instead of xrange, and also importing old_div, which mimics Python2's division for both Python 2 and 3. What would be preferable is to from __future__ import division (which enables Python 3's division), and then using either // or / depending on if you want integer division or not. See here for details. I'm not really able to tell from your code which kind of division you want. I assume it's not floor division //, but I'm not certain.
Basically what I did here was run
futurize -w . --stage2
on the code, see http://python-future.org/futurize.html for details.The main changes are importing the new
range
function and using that instead ofxrange
, and also importingold_div
, which mimics Python2's division for both Python 2 and 3. What would be preferable is tofrom __future__ import division
(which enables Python 3's division), and then using either//
or/
depending on if you want integer division or not. See here for details. I'm not really able to tell from your code which kind of division you want. I assume it's not floor division//
, but I'm not certain.