This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Misleading [i:j:k] slicing description
Type: Stage:
Components: Documentation Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: mwh Nosy List: mwh, raoulgough, rhettinger, tzot
Priority: normal Keywords:

Created on 2003-08-21 18:02 by raoulgough, last changed 2022-04-10 16:10 by admin. This issue is now closed.

Messages (4)
msg17873 - (view) Author: Raoul Gough (raoulgough) Date: 2003-08-21 18:02
Section 2.2.6 (Sequence types), note 5 from the table 
says:

  "The slice of s from i to j with step k is defined as the 
sequence of items with index x = i + n*k such that 0 
<= n < abs(i-j). [...]"

However, n should only range up to (j-i)//k

Note also that (j-i)//k correctly specifies the results for 
negative values of k, and empty sequence returns 
where signof(j-i) != signof (k). Maybe worth mentioning 
that k != 0  (!! :-)
msg17874 - (view) Author: Χρήστος Γεωργίου (Christos Georgiou) (tzot) * Date: 2003-08-29 09:57
Logged In: YES 
user_id=539787

See patch 797180 http://www.python.org/sf/797180

the above is changed to:

such that \code{0} \code{<=} \var{n} \code{<} \code{abs
(j-i)//k} (\code{k} cannot be zero).
msg17875 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-08-30 23:42
Logged In: YES 
user_id=80475

Applied Tzot's patch.
mwh can re-open if anything else needs to be done.
msg17876 - (view) Author: Raoul Gough (raoulgough) Date: 2003-08-31 14:17
Logged In: YES 
user_id=543196

I don't understand this determination to use abs. If I have s
[5:1:1], the result is empty, but the spec actually says that 
the result is [s[5], s[6], s[7], s[8]], using 0 <= n < abs(1-
5)/1. Related problem with s[5:1:-1], where the spec says 
0<=n<abs(1-5)/-1, i.e. 0<=n<-4 giving an empty results 
instead of the correct [s[5],s[4],s[3],s[2]]
History
Date User Action Args
2022-04-10 16:10:45adminsetgithub: 39102
2003-08-21 18:02:53raoulgoughcreate