| Store | Cart

Re: [Python-Dev] List insert at index that is well out of range - behaves like append

From: Antoine Pitrou <soli...@pitrou.net>
Tue, 16 Sep 2014 00:54:03 +0200
On Mon, 15 Sep 2014 23:46:03 +0100
Mark Lawrence <brea...@yahoo.co.uk> wrote:
> > I assume it's based on the concepts of slicing.  From the docs > "s.insert(i, x) - inserts x into s at the index given by i (same as > s[i:i] = [x])".  Although shouldn't that read s[i:i+1] = [x] ?

No, the latter would replace the contents at index i, while the former
inserts it (formally, it replaces the 0-length slice with a 1-length
slice).

Regards

Antoine.


_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Harish Tech Sep 15, 2014 03:18 am
Tal Einat Sep 15, 2014 11:31 am
Harish Tech Sep 15, 2014 12:17 pm
Mark Shannon Sep 15, 2014 10:29 pm
Mark Lawrence Sep 15, 2014 10:46 pm
Ethan Furman Sep 15, 2014 10:53 pm
Antoine Pitrou Sep 15, 2014 10:54 pm
Guido van Rossum Sep 15, 2014 10:57 pm
Guido van Rossum Sep 15, 2014 10:54 pm
Messages in this thread