0

I have a problem with appending to two lists. I tried to append one tuple to queue and second tuple to queue_end, but when i pop from both queue's the output is the same.

The first tuple is lost somehow and when i try to pop from both queue's, it pops the same state.

Where could be problem ?

queue = []
queue.append((0, node(2, 3, 0, [[0,1,2],[3,4,5]]))) # creating object node and appending a tuple to queue

queue_end = []
queue_end.append((0, node(2, 3, 0, [[3,4,5],[0,1,2]])))

state = queue.pop(0)
state_2 = queue_end.pop(0)

print(state[1].state)
print(state_2[1].state)

Output

[[3, 4, 5], [0, 1, 2]]

[[3, 4, 5], [0, 1, 2]]

Desired Output

[[0, 1, 2],[3, 4, 5]]

[[3, 4, 5], [0, 1, 2]]

How could [[3, 4, 5], [0, 1, 2]] be appended into queue ? [[0,1,2],[3,4,5]] should be in queue.

The class node:

class node:
  m = n = 0
  state = [[m],[n]]
  previous_node = 0
  not_in_place = -1

  def __init__(self, m, n, previous_node, listt=None):
      self.m = m
      self.n = n
      self.previous_node = previous_node
      if listt is not None:
          for i in range(self.m):
              self.state[i] = listt[i] 
              self.state[i] = listt[i]

0 Answers0