range() is not the best way to check range?
Dan Bishop
danb_83 at yahoo.com
Tue Jul 18 11:05:37 EDT 2006
Paul Boddie wrote:
> Yes, he wants range to return an iterator, just like xrange more or
> less does now. Given that xrange objects support __getitem__, unlike a
> lot of other iterators (and, of course, generators), adding
> __contains__ wouldn't be much of a hardship. Certainly, compared to
> other notational conveniences bounced around on the various development
> lists, this one would probably provide an order of magnitude
> improvement on the usual bang per buck development ratio.
xrange already has __contains__. The problem is, it's implemented by a
highly-inefficient sequential search. Why not modify it to merely
check the bounds and (value - start) % step == 0?
More information about the Python-list
mailing list