[C++-sig] Re: New slice implementation
David Abrahams
dave at boost-consulting.com
Fri Jan 9 17:39:48 CET 2004
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]
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list