'how to make a value in a matrix refer to the relation between the columd and the row

in this table i have the distance between places (pan= panama etc ) enter image description here

i have found each possible route with a permutation resaulting in 120 possibilities

routes = permutations(["pan","ams", "cas" ,"nyc" , "hel"])
for i in routes:
print(i)

i tried puting the data from the icon like this

  D =  [
       [0,8943,8019,3652,10545],
       [8943,0,2619,6317,2078],
       [8019,2619,0,5836,4939],
       [3652,6317,5836,0,7825],
       [10545,2078,4939,7825,0]
       ]

and now i have to find which of my possible routes is the shortest distance.

i cant understand how to make my program know that the d[0],[0] is the distance pan -pan or that the d1,[0] the distance ams- pan i mean each data in the matrix isnt just one number for use ,but the distance between 2 places from my routes.

its burning my brain !



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source