[Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

Alan Gauld alan.gauld at btinternet.com
Sat Jan 16 18:56:43 EST 2016


On 16/01/16 22:39, boB Stepp wrote:

> So in this model of understanding negative list indexing, should it be:
> 
> mylist = [ 100, 200, 300, 400, 500 ]
>           ^    ^    ^    ^    ^   ^
>           -5   -4   -3   -2   -1  ?
> 
> Well, it has to be this; otherwise, the off-by-one error exist.  This
> also continues to explain why
> 
> mylist.insert(-1, x)
> 
> inserts x *before* 500.  But in this model, what should go in the place of "?"?

-0

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list