[New-bugs-announce] [issue28336] Slicing (operation) is not symmetrical with respect to suffixes and prefixes

Juan Carlos Pujol Mainegra report at bugs.python.org
Sat Oct 1 14:57:29 EDT 2016


New submission from Juan Carlos Pujol Mainegra:

Let s be a string or other array-like object, a, b > 0 integers, s[0:b] returns a b-long prefix to s, the same as s[:b], but s[-a:0] returns empty (for len(s) > 0 and a > 1), while it should return the same as s[-a:], an a-long suffix (a > 0).

A syntax asymmetry like this shall not be imposed to those using non-literal slicing indexes, as it would be necessarily to introduce a control condition to test whether the upper bound index is a non-negative quantity, assuming the lower bound index is negative. Furthermore, it breaks the whole negative slicing idea, being that (I consider) index i always be treated as i mod len(s), so that constructions like s[-a:b] (for a, b > 0 or a, b < 0) could return s[-a:] + s[:b].

----------
components: Interpreter Core
messages: 277829
nosy: jksware
priority: normal
severity: normal
status: open
title: Slicing (operation) is not symmetrical with respect to suffixes and prefixes
type: enhancement
versions: Python 3.6

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


More information about the New-bugs-announce mailing list