Use range instead of xrange for py3 compatibility