I am trying to append a list into another list however I cannot seem to make it work.
Here is the code. When I run it and print Q for each iteration of the while loop I get something like [2,3] [2] [3,4] etc. And I want to append these lists into the list my_Q by doing my_Q.append(Q). However, this returns me this: my_Q = [0, [], [], [] ]
import random
#Matrix Input
M = 10**3
G = [ [M, 5, 9, M],
[M, M, 1, 10],
[M, M, M, 4],
[M, M ,M, M] ]
#Initialize
Q = [1]
l = [0, M, M, M]
A = [1, 2, 3, 4]
iter = 0
#For display
my_v = [0]
my_Q = [1]
#Algorithm
while Q: #Stop conditions
iter += 1
#Step 2:
v = random.choice(Q)
Q.remove(v)
#Step 3:
for w in A:
l_new = min(l[w-1], l[v-1] + G[v-1][w-1])
if l_new != l[w-1]:
if w not in Q:
Q.append(w)
l[w-1] = l_new
#Save for display
my_v.append(v)
print(Q)
my_Q.append(Q)
print(my_Q)