I was trying to do following operation on a list 2 times:
-> for each index i: arr[i] = d - arr[i] where d is maximum element in list
-> append the resultant list to another list
My code:
arr = [5, -1, 4, 2, 0]
n = len(arr)
res = []
for _ in range(2):
d = max(arr)
for i in range(n):
arr[i] = d-arr[i]
res.append(arr)
print(res)
Output:
[[6, 0, 5, 3, 1], [6, 0, 5, 3, 1]]
Expected Output:
[[0, 6, 1, 3, 5], [6, 0, 5, 3, 1]]
Please help!