[issue15224] Range: Additional Methods (min/max/__and__)
Yclept Nemo
report at bugs.python.org
Fri Jun 29 18:37:03 CEST 2012
New submission from Yclept Nemo <orbisvicis at 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)
c=a&b
print(c)
Range(21, 69, 12)
list(c)
[21, 33, 45, 57]
intersection #2:
a=Range.Range(-75,-7,4)
b=Range.Range(-111, -26, 6)
c=a&b
print(c)
Range(-75, -15, 12)
list(c)
[-75, -63, -51, -39, -27]
intersection #3:
a=Range.Range(58,9,-4)
b=Range.Range(15,69,6)
c=a&b
print(c)
Range(0, 0, 1)
list(c)
[]
I've attached an example Range class implemented in python that includes the min, max, and __and__ functions. It should be useful because the intersection algorithm is complicated. Extending the range class was a requirement for a python 3.2 project and hopefully python 3.4 can benefit.
----------
components: None
files: Range.py
messages: 164333
nosy: Yclept.Nemo
priority: normal
severity: normal
status: open
title: Range: Additional Methods (min/max/__and__)
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file26209/Range.py
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15224>
_______________________________________
More information about the Python-bugs-list
mailing list