[Patches] [ python-Patches-873305 ] list.__setitem__(slice) behavior

SourceForge.net noreply at sourceforge.net
Sat Mar 13 16:16:28 EST 2004


Patches item #873305, was opened at 2004-01-08 15:46
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=873305&group_id=5470

Category: None
Group: None
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Jonathan Brandmeyer (jbrandmeyer)
Assigned to: Nobody/Anonymous (nobody)
Summary: list.__setitem__(slice) behavior

Initial Comment:
Consider the following:
>>> x = [0, 1, 2, 3, 4]
>>> x[-1:0] = [5, 6, 7]

Currently the result is that x == [0,1,2,3,5,6,7,4]. 
However, I believe that calling setitem with an empty
slice should be a no-op, rather than performing an
insertion starting at the 'begin' index of the slice.

The following patch to Objects/listobject.c makes this
change.

Thanks,
Jonathan Brandmeyer

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-03-13 16:16

Message:
Logged In: YES 
user_id=80475

I believe we are stuck with this one.  Assigning to an empty
slice like a[2:2]=list('hotdog') is a valid and useful.  The
weird part is that the rightmost index gets adjusted to make
the most sense given the leftmost index.  In your example,
the offerred indices of -1 and 0 would seem to indicate a
programming error.  However, this autoadjusting is a long
standing feature and occassionally useful in its own right.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=873305&group_id=5470



More information about the Patches mailing list