Adding item in front of a list

Tim Peters tim.one at comcast.net
Wed Apr 9 17:23:51 CEST 2003


[Andrew Koenig, starting with l=[2, 3, 4]]
> ...
> I would have thought that after l.insert(-1, 1), l would be
> [2, 3, 1, 4], but it doesn't work that way.

Alas, list.insert() existed before sequence indices were generalized to give
a "count from the right end" meaning to negative index values.  When the
generalization happened, it appears that list.insert() was just overlooked.

I'd like to change this.  If I did, how loudly would people scream?

Guido says he also wishes list.insert() had been defined with the arguments
in the opposite order, so that list.insert(object) could have a natural
default index argument of 0.  I'd like to change that too, but it's clearly
too late for that one.






More information about the Python-list mailing list