Odd slicing behavior?

Dave Opstad dave.opstad at monotypeimaging.com
Wed Jun 22 16:24:56 EDT 2005


In article <3htv6gFips59U1 at uni-berlin.de>,
 "Diez B. Roggisch" <deets at web.de> wrote:

> So - the rationale seems to be: "When using slice-assignment, a form 
> like l[a:b:c] imposes possibly a non-continous section in l, for which 
> the semantics are unclear - so we forbid it"

But it isn't forbidden:

>>> v = range(10)
>>> v
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> v[0:10:3] = ['a', 'b', 'c', 'd']
>>> v
['a', 1, 2, 'b', 4, 5, 'c', 7, 8, 'd']

The only time it's actively forbidden is when the length of the slice 
and the length of the list being assigned to it don't match.

I agree with you that it might be nice for [a:b:1] and [a:b] to be 
treated synonymously.

Dave



More information about the Python-list mailing list