def deep_reverse(L) :
for i in range (len(L)-1,-1,-1):
L=L[::-1]
for i in range (len(L)-1,-1,-1):
L[i]=L[i][::-1]
L = [[0, 1, 2], [1, 2, 3], [3, 2, 1], [10, -10, 100]]
deep_reverse(L)
print(L)
So I have this code here and a function called deep_reverse(L). I am trying to mutate the list L, at the end when i print(L)
it prints out L = [[0, 1, 2], [1, 2, 3], [3, 2, 1], [10, -10, 100]]
. However, when I print from within the function, I get L= [[2, 1, 0], [3, 2, 1], [1, 2, 3], [100, -10, 10]]
, which is what I want. How can i permanently mutate L so that it stays that way when I print it outside the function.
question from:
https://stackoverflow.com/questions/65928411/how-to-mutate-list-permanently 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…