"spir" wrote
s = [1,2,3,4,5,6,7,8,9]
print s, s[-3], s[-4] # [1, 2, 3, 4, 5, 6, 7, 8, 9] 7 6
s.insert(-3, 0)
print s, s[-3], s[-4] # [1, 2, 3, 4, 5, 6, 0, 7, 8, 9] 7 0
So, I did insert 0 at index -3, but s[-3] is still 7, & 0 is in fact at
index -4.
Seems reasonable. insert() inserts befor
On Wed, Jan 6, 2010 at 8:54 AM, spir wrote:
> Hello,
>
> Just found something rather misleading with negative indices:
>
> s = [1,2,3,4,5,6,7,8,9]
> print s, s[-3], s[-4] # [1, 2, 3, 4, 5, 6, 7, 8, 9] 7 6
> s.insert(-3, 0)
> print s, s[-3], s[-4] # [1, 2, 3, 4, 5, 6, 0, 7, 8, 9] 7 0
>
> So, I
Hello,
Just found something rather misleading with negative indices:
s = [1,2,3,4,5,6,7,8,9]
print s, s[-3], s[-4] # [1, 2, 3, 4, 5, 6, 7, 8, 9] 7 6
s.insert(-3, 0)
print s, s[-3], s[-4] # [1, 2, 3, 4, 5, 6, 0, 7, 8, 9] 7 0
So, I did insert 0 at index -3, but s[-3] is still 7, & 0 is in fact