A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-August/017291.html below:

[Python-Dev] Negative index in insert()

[Python-Dev] Negative index in insert()Eric S. Raymond esr@thyrsus.com
Fri, 24 Aug 2001 19:51:56 -0400
Given 

>>> a = [1, 2, 3, 4]

because

>>> a[-2]
-3

I expected that a.insert(-2, 0) would yield [1, 2, 0, 3, 4].  It was a 
rude shock to discover that 

>>> a
[0, 1, 2, 3, 4]

In fact I think this may be the nastiest surprise Python has handed me since
I started using it.  

The reference manual says "same as s[i:i] = [x]  if i >= 0" which of course
doesn't cover the i < 0 case.  David Beasley's reference says "Inserts x 
at index i" which sounds like the behavior I was expecting but didn't get.

Is this a deliberate design choice, an oversight, or a plain bug?  If it's
a choice, it's damn poorly documented -- this deserves at least a footnote
in the list methods table.  If it's an oversight or bug, I volunteer to fix it.
-- 
		<a href="http://www.tuxedo.org/~esr/">Eric S. Raymond</a>

"America is at that awkward stage.  It's too late to work within the system,
but too early to shoot the bastards."
	-- Claire Wolfe



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4