0

There are several other questions with nearly the same title, please read the full question.
I'm trying to shift a list in python to the right, and then modifying array[0], however doing this results in modifying both array[0] and array[1]:

arr = [[91, 3], [90, 3], [89, 3], [88, 3], [87, 3]]

pairs = enumerate
def shiftArray(a):
    o = a[0]
    for i in range(len(a)-1, -1, -1):
        a[i] = a[i-1]
    a[0] = o
    return a
shiftArray(arr)
arr[0][0] += 1
print(arr) # [[92, 3], [92, 3], [90, 3], [89, 3], [88, 3]]
  • Welcome to Stack Overflow. The problem is that `a[0]` and `a[1]` are **the same list object**. Please see the linked duplicates to understand how to avoid the problem, by creating a separate list with the same value. – Karl Knechtel Oct 12 '22 at 04:14
  • What does your desired output look like? – Timo Oct 12 '22 at 06:07

0 Answers0