Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information. >>> u = [4, 5, 6, 7, 8, 9] >>> u[1::1] = [3, 2, 1, 0] >>> u [4, 3, 2, 1, 0] >>> u[9:0:-1] = [8, 7, 6, 5] >>> u [4, 5, 6, 7, 8] >>> u[9:0:-1] = [16, 12, 8] Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: attempt to assign sequence of size 3 to extended slice of size 4 >>> u [4, 5, 6, 7, 8] >>>
Expected Behavior: An exception is not thrown for the final assignment operation; u
should print on the last line as [4, 8, 12, 16]
.
I can assign an extended slice whose step is 1, even if the iterability that I assign is "the wrong length". Why then can I not assign an extended slice whose step is -1, and does it work in an obvious way?