Fairly self explanatory, see the diff in the code.
Py3 defaults to float division so n/2 would return a float which is later used in range function that throws an error cause it knows not what to do with it.
Similarly, in weighted average calculation, weights is a map object in py3.
The implementation of weighted_average tries to traverse this object twice which means that the second time it traverses it (namely when computing the sum), the object is empty.
Thus the sum is always 0 and we get a division-by-zero exception.
This change looks good. I've been working on Py3 compatibility in other areas as I prepare unit tests. I haven't quite gotten around to unit testing this component yet.
Fairly self explanatory, see the diff in the code. Py3 defaults to float division so
n/2
would return a float which is later used inrange
function that throws an error cause it knows not what to do with it.Similarly, in weighted average calculation,
weights
is amap
object in py3. The implementation ofweighted_average
tries to traverse this object twice which means that the second time it traverses it (namely when computing thesum
), the object is empty. Thus the sum is always 0 and we get a division-by-zero exception.