Recently I started using Python3 and it’s lack of xrange
hurts.
Simple example:
-
Python2:
from time import time as t def count(): st = t() [x for x in xrange(10000000) if x%4 == 0] et = t() print et-st count()
-
Python3:
from time import time as t def xrange(x): return iter(range(x)) def count(): st = t() [x for x in xrange(10000000) if x%4 == 0] et = t() print (et-st) count()
The results are, respectively:
1.53888392448
3.215819835662842
Why is that? I mean, why xrange
has been removed? It’s such a great tool to learn. For the beginners, just like myself, like we all were at some point. Why remove it? Can somebody point me to the proper PEP, I can’t find it.