It is easy to assign the same scalar value to every element of a slice of a numpy array, but not so easy for a python list: somenparray[start::step]=42
Doing that to a slice of python list requires specifying how many elements are in the slice: somelist[start::step]=lenslice*[42] # You have to figure out lenslice
and create a list of that length.
Further example:
import numpy as np
def lenpositiverange(start,limit,step): # how many items in the slice or range for posiive steps
return (limit - start + step - 1 ) // step
n=10000
npbools = np.ones((n,),dtype=bool)
bools=n*[True]
npbools[49::7] = False # Valid way to assign scalar to every element of a slice of an numpy array.
# Note that the slice parameters do not need to specify the upper limit.
# bools[49::7] = False # TypeError: must assign iterable to extended slice
# bools[49::7]= [False] # ValueError: attempt to assign sequence of size 1 to extended slice of size 1422
bools[49:n:7]=lenpositiverange(49,n,7) * [False] # Valid, must specify the upper limit. This is inconvenient.
Request: Allow assigning a scalar to all elements of a list slice, just as is allowed with a numpy array.