-1

I have a list of edges l=[(0,1),(0,2),(1,3)] likewise, and I have list of weight of edges l1=[0.23,0.45,0]. Now I wanted to store edges in min heap manner, so that I can get access to minimum weighted edge.

1 Answers1

0

Now i got it, using heapq and do heapify.

First create list

l = [[0.23, (0, 1)], [0.45, (0, 2)], [0, (1, 3)]]

Then call

heapq.heapify(l)

Returning:

[[0, (1, 3)], [0.23, (0, 1)], [0.45, (0, 2)]]
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 18 '21 at 18:32