Serhiy Storchaka storch...@gmail.com added the comment:
On a side note, glancing at Python-3.3.0a4/Objects/rangeobject.c:
range_contains seems to iterate through the entire range whereas __contains__
from the attached Range.py is O(1)
See issue1766304. For int range.__contains__ is O(1),
Mark Dickinson dicki...@gmail.com added the comment:
However, the concept of the intersection of ordered sets is commonplace
and implemented in other libraries, for example:
None of those are specific to arithmetic progressions (i.e., range-like lists /
sets), as far as I can tell. I could
Yclept Nemo orbisvi...@gmail.com added the comment:
None of those are specific to arithmetic progressions (i.e., range-like
lists / sets), as far as I can tell.
Does this (the data-type involved) really matter?
I could see more use for general list-intersection functionality.
The way to
Mark Dickinson dicki...@gmail.com added the comment:
Okay, I'm closing this as rejected. Some responses:
I don't think that complexity or specialisation should matter.
Well, Python's supposed to be a general-purpose language; range objects *are*
generally useful for all sorts of tasks, but
Raymond Hettinger raymond.hettin...@gmail.com added the comment:
FWIW, I concur with rejecting this for the reasons that Mark mentioned.
--
nosy: +rhettinger
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15224
New submission from Yclept Nemo orbisvi...@gmail.com:
Python 3.3 expands the range class but I would find some additional methods
useful:
min/max: provides O(1) time
__and__: provides intersection: Range(...) Range(...)
examples:
intersection #1:
a=Range.Range(9,58,4)
b=Range.Range(15,69,6)
Mark Dickinson dicki...@gmail.com added the comment:
max and min for a range object are already O(1) one-liners:
a = range(3, 21, 5)
a[-1] if a.step 0 else a[0] # max(a)
18
a[0] if a.step 0 else a[-1] # min(a)
3
As for __and__, it doesn't feel like a particularly natural operation to
Yclept Nemo orbisvi...@gmail.com added the comment:
max and min for a range object are already O(1) one-liners:
true; dropping
As for __and__, it doesn't feel like a particularly natural operation to me,
given that a range object represents an *ordered* sequence of integers rather
than
Yclept Nemo orbisvi...@gmail.com added the comment:
a=Range.Range(5,61,4)
ar=Range.Range(57,1,-4)
b=Range.Range(21,63,6)
br=Range.Range(57,15,-6)
list(a); list(ar); list(b); list(br)
[5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57]
[57, 53, 49, 45, 41, 37, 33, 29, 25, 21, 17, 13, 9,
Yclept Nemo orbisvi...@gmail.com added the comment:
On a side note, glancing at Python-3.3.0a4/Objects/rangeobject.c:
range_contains seems to iterate through the entire range whereas __contains__
from the attached Range.py is O(1)
--
___
Python
10 matches
Mail list logo