I am creating a graph of minimum heap queues and when I read input like this:
3
1 2 7
6 5 4
3 8 9
Into this python program:
n = int(input())
G = {}
for u in range(n):
line = input().split()
minimum_q = []
for v in range(len(line)):
if u != v:
w = int(line[v])
#obj = {w, (u, v)}
#heappush(minimum_q, obj)
heappush(minimum_q, (w, (u, v)))
G[u] = minimum_q
I get some weird behavior. When the obj variable is created to be pushed into the queue, the object looks like this: obj: {(0, 1), 2} This is anticipated, but when I get to the element "8" in which u = 2, v = 1, w = 8. But the obj looks like this: {8, (2, 1)}
Does anyone have any ideas?
edit: Changed the code to what worked.