-1

I'm trying to convert my inputted data from

g.addEdge(0, 1, 7) 
 g.addEdge(1, 2, 9) 
 g.addEdge(2, 0,14)

into

g.graph = [
        [ 0,  7,  0], 
        [ 0,  0,  9], 
        [ 14, 0, 0,],  
    ]

simply, the first and second number as the coordinate to place the last number.

I'm begging for your help, please

ZawKey
  • 3
  • 3
  • 2
    Does this answer your question? [Prim's Minimum Spanning Tree on Python](https://stackoverflow.com/questions/67758530/prims-minimum-spanning-tree-on-python) – Nir Alfasi May 30 '21 at 08:57
  • Please don't SPAM by creating duplicates of questions you've already asked. Instead, take the time to improve your question and there are better chances you'll get an answer! – Nir Alfasi May 30 '21 at 08:57

1 Answers1

0

Try to create matrix NxN where N is number of edges. You can create matrix as list that contains lists. After that make addEdge function that will just put last argument on x and y positions that are represented with first and second argument.

Maybe something like this:

g.graph = [[0 for x in range(N)] for y in range(N)] 

def addEdge(x, y, num):
   g.graph[x][y] = num

Also, I don't think your example is right because x and y coordinates aren't right, please check all that.

Milos Stojanovic
  • 172
  • 2
  • 11