我正在學習Python,並一直試圖使一個雙動力。然而,我得到不正確的輸出,我不知道爲什麼。我的代碼如下:Python deque範圍?
p = [2, 1], [1, 1]
init_q= deque()
init_q.append(p)
for i in range(len(p)):
for j in range(len(p[i])):
temp = p[i][j]
p[i][j] = 0
init_q.append(p)
p[i][j] = temp
while init_q:
print init_q.pop()
在這段代碼我需要在列表中,然後,我想創建一個隊列5名單,其中有4個在不同的位置對他們有一個0,結果我要的是:
([2, 1], [1, 1])
([0, 1], [1, 1])
([2, 0], [1, 1])
([2, 1], [0, 1])
([2, 1], [1, 0])
但是,結果我得到的是:
([2, 1], [1, 1])
([2, 1], [1, 1])
([2, 1], [1, 1])
([2, 1], [1, 1])
([2, 1], [1, 1])
您確定預期的輸出不是向後? – abarnert