[Python-bugs-list] [ python-Bugs-684022 ] extended slice strangeness
SourceForge.net
noreply@sourceforge.net
Mon, 10 Feb 2003 10:19:51 -0800
Bugs item #684022, was opened at 2003-02-10 16:54
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=684022&group_id=5470
Category: Python Interpreter Core
Group: Python 2.3
Status: Closed
Resolution: Rejected
Priority: 5
Submitted By: Robert Roy (rjroy)
Assigned to: Michael Hudson (mwh)
Summary: extended slice strangeness
Initial Comment:
I was playing with extended slices and wanted to see if
it would return a reversed slice. The behaviour was not
quite what I expected. See the following
Python 2.3a1 (#38, Dec 31 2002, 17:53:59) [MSC
v.1200 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> l = range(12)
>>> l
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
## this works as expected
>>> l[0:5:2]
[0, 2, 4]
## this returns empty list ??
>>> l[0:5:-1]
[]
## this works as expected
>>> l[::-1]
[11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
## I would expect this to return same as above
>>> l[0::-1]
[0]
## would expect empty list since l[5:0] == []
>>> l[5:0:-1]
[5, 4, 3, 2, 1]
## would expect [11, 10, 9, 8, 7, 6,5]
>>> l[5::-1]
[5, 4, 3, 2, 1, 0]
>>>
----------------------------------------------------------------------
>Comment By: Michael Hudson (mwh)
Date: 2003-02-10 18:19
Message:
Logged In: YES
user_id=6656
Hmm. The thing is, it's more or less up to the types as to
what they do with the indices. ref3.tex refers to them as
start:stop:step and that seems good enough for me.
The libconsts thing is about Ellipsis; I know nothing about
that except that it's to do with multi-rank "sequences".
Ask the numpy folks, if you care.
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2003-02-10 18:11
Message:
Logged In: YES
user_id=33168
I don't have a problem with your answer. I looked through
ref3.tex and didn't see anything in particular about negative
steps. Should something be added? If so, is ref3 the
correct place?
There's a comment in libconsts:
% XXX Someone who understands extended slicing should fill
in here.
----------------------------------------------------------------------
Comment By: Michael Hudson (mwh)
Date: 2003-02-10 17:50
Message:
Logged In: YES
user_id=6656
the interpretation of
l[start:stop:step]
is similar to that of
range(start, stop, end)
An omitted an index means the endpoint and what that means
changes with the sign of step. You have to have this to
make l[::-1] do what you want.
So I'm going to reject this. Feel free to reopen if you
disagree wildly, but you'll have to talk fast.
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2003-02-10 17:12
Message:
Logged In: YES
user_id=33168
I'm not sure what I would expect. Your suggestions seem
reasonable. Michael?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=684022&group_id=5470