[issue15224] Range: Additional Methods (min/max/__and__)

Mark Dickinson report at bugs.python.org
Fri Jun 29 19:02:26 CEST 2012


Mark Dickinson <dickinsm at 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 me, given that a range object represents an *ordered* sequence of integers rather than just a subset.  For example, what should the first element of

  range(7, -3, -2) & range(10)

be? 7 or 1? And why?

----------
nosy: +mark.dickinson

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15224>
_______________________________________


More information about the Python-bugs-list mailing list