[C++-sig] Re: New slice implementation
Jonathan Brandmeyer
jbrandmeyer at earthlink.net
Fri Jan 9 18:31:11 CET 2004
On Fri, 2004-01-09 at 11:39, David Abrahams wrote:
> Jonathan Brandmeyer <jbrandmeyer at earthlink.net> writes:
>
> >> I don't think I agree with what you're saying here. Would you agree
> >> that __getitem__ from e.g. lst[4:2] should be an empty sequence?
> >>
> >> Quoting from http://www.python.org/doc/current/lib/typesseq.html
> >>
> >> "(4) [...] If i is greater than or equal to j, the slice is empty."
> >
> > Section 5.3.3 of the Python Language Reference includes: "The slicing
> > now selects all items with index k such that i <= k < j where i and j
> > are the specified lower and upper bounds. This may be an empty
> > sequence."
> >
> > I claim that not only are there no elements to be replaced in the case
> > of __setitem__ with such a slice, but that this doesn't clearly define a
> > point to insert new elements, either.
>
> Doesn't the following pretty much settle the question of what the
> Pythonic behavior is?
> $ python
> Python 2.3.2 (#1, Nov 14 2003, 18:13:01)
> [GCC 3.3.1 (cygming special)] on cygwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> l = range(100,120)
> >>> l[5:2] = range(6)
> >>> l
> [100, 101, 102, 103, 104, 0, 1, 2, 3, 4, 5, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119]
Yes it does. Maybe I'm being arrogant here, but I think that behavior
is wrong, and I think it strongly enough that I submitted a patch to
Python to change it.
I think at this point we should just let this argument rest for a bit
pending the resolution of the patch I submitted to Python, or at least,
to move any additional comments to the sourceforge tracker for that
patch.
-Jonathan Brandmeyer
More information about the Cplusplus-sig
mailing list