Why is there no xrange function in Python3?

Some performance measurements, using timeit instead of trying to do it manually with time. First, Apple 2.7.2 64-bit: In [37]: %timeit collections.deque((x for x in xrange(10000000) if x%4 == 0), maxlen=0) 1 loops, best of 3: 1.05 s per loop Now, python.org 3.3.0 64-bit: In [83]: %timeit collections.deque((x for x in range(10000000) if x%4 == … Read more

Better to ‘try’ something and catch the exception or test if it’s possible first to avoid an exception?

You should prefer try/except over if/else if that results in speed-ups (for example by preventing extra lookups) cleaner code (fewer lines/easier to read) Often, these go hand-in-hand. speed-ups In the case of trying to find an element in a long list by: try: x = my_list[index] except IndexError: x = ‘NO_ABC’ the try, except is … Read more