I want to make a slice of array and then assign each element of a slice to a number and then update according to indices I provide.
For example:
[0, 0, 0, 0, 0] --> initial array
I want to assign 100 to first two elements i.e
a[0:2] = 100 for j in range(0,2)
so now the array becomes
[100, 100, 0, 0, 0]
now if i want to add 100 to the first three elements so the array should now become
[200, 200, 100, 0, 0]
what's the correct way to do this? I am getting a syntax error for the following code:
def arrayManipulation(n, queries):
n = 10
//queries is list of [[starting index, ending index, value to be updated]]
initialArray = [0]*n;
for i in queries:
firstIndex = i[0]-1
secondIndex = i[1]
initialArray[firstIndex:secondIndex] = ((initialArray[j] += i[2]) for j in range(firstIndex, secondIndex))
print(initialArray)