[Python-3000] optimizing [x]range (original) (raw)
tomer filiba tomerfiliba at gmail.com
Sun Jul 29 14:48:21 CEST 2007
- Previous message: [Python-3000] optimizing [x]range
- Next message: [Python-3000] optimizing [x]range
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
i understand there is no much need for using ranges instead of intervals (a < x < b), but:
it's already supported. you CAN use x in range(100), so why not optimize it? there's no justification to keep it an O(N) operation (you're not trying to punish anyone :). it just calls for adding a contains slot to range objects. the cost is very minimal.
ranges are more like set-builder notation, i.e. evens = {2*n | n in N} which can be written as evens = range(0, maxint, 2) odds = range(1, maxint, 2) you cannot phrase "x in odds" in "a <= x < b" notation. sure, just use modulu, but then it just gets ugly.
if range (== xrange) would be a cheap, O(1) operation, there's not reason to to use it when it suits well.
-tomer
On Jul 29, 12:04 am, "Guido van Rossum" <gu... at python.org> wrote:
Do we really need another way to spell a <= x < b? Have you got a_ _real-world use case in mind for the version with step > 1?
I'm at most lukewarm; I'd be willing to look at a patch to the C code in the py3k-struni branch, plus unit tests though. --Guido
- Previous message: [Python-3000] optimizing [x]range
- Next message: [Python-3000] optimizing [x]range
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]