[issue28423] list.insert(-1,value) is wrong!

Tim Peters report at bugs.python.org
Wed Oct 12 18:01:43 EDT 2016


Tim Peters added the comment:

It's fine.  Read the docs.  "s.insert(i, x) inserts x into s at the index given by i (same as s[i:i] = [x])"

Note that:

>>> fred[-1:]
[4]

So the empty slice s[-1:-1] is _between_ 3 and 4 in `fred`.  If you're not surprised by

>>> fred[-1]
4

then you shouldn't be surprised by what `fred.insert(-1, whatever)` does either ;-)

----------
nosy: +tim.peters
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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


More information about the Python-bugs-list mailing list