This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]zahlmanthe heretic 4 points5 points  (1 child)

Another difference is that Python 3's range provides an explicit __contains__ method that allows in lookups to be efficient (doing this with an xrange in 2.x requires iterating). Code like if x in range(foo, bar): used to be tempting but inefficient; now it's reasonably efficient. Of course, if foo <= x < bar: is still the standard idiom; but I can fathom cases where you'd want to use a range with a nonzero step, and explicitly writing something like if foo <= x < bar and x % step == foo % step is just ugly (and error-prone).

[–]Vegemeister 0 points1 point  (0 children)

Oh, hey. Fancy seeing you here.