From: MRAB on
Robert William Hanks wrote:
> why pure python don't support "extended slice direct assignment" for lists?
>
> today we have to write like this,
>
> >>> aList=[0,1,2,3,4,5,6,7,8,9]
> >>> aList
> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
> >>> aList[::2]= [None]*len(aList[::2]) #or do the math by hand, what's
> not always possible
> >>> aList
> [None, 1, None, 3, None, 5, None, 7, None, 9]
>
> why not accept syntax like this for extended slice
>
> aList[::2] = None
>
> when let's say, the left side is a list and the right side is bool, int
> or float.
> the laborious [nunber]*len(aList[::2]) seens to me less readable when
> you want to set lost of items of a list to the same number.
> Also correct me if i am wrong, calling len() and building a list to this
> kind of operation seems a waste.
>
> Just want some feedback.
>
When you're assigning to a list slice, why should it duplicate an int
but not a list? Or in general, duplicate something that's not iterable
but not something that is iterable? A string is iterable, so what
should:

>>> a[ : : 2] = "abcde"

do?

It's just simpler and less surprising the way it is.