replace range with xrange

adapt to python 2.7 convention