Getting below error when executing the python code given. Tried adding list but it still throws the same error.
---------------------------------------------------------------------------
--> 204 dist[i][j] = min(dist[i][j] ,dist[i][k]+ dist[k][j] )
TypeError: 'map' object is not subscriptable
Please help in resolving this
V = 4
INF = 99999
def floydWarshall(graph):
dist = map(lambda i : map(lambda j : j , i) , graph)
for k in range(V):
# pick all vertices as source one by one
for i in range(V):
for j in range(V):
dist[i][j] = min(dist[i][j] ,dist[i][k]+ dist[k][j] )
printSolution(dist)
def printSolution(dist):
print ("Following matrix shows the shortest distances between every pair of vertices")
for i in range(V):
for j in range(V):
if(dist[i][j] == INF):
print ("%7s" %("INF"),)
else:
print ("%7d\t" %(dist[i][j]),)
if j == V-1:
print ("")
graph = [[0,5,INF,10],
[INF,0,3,INF],
[INF, INF, 0, 1],
[INF, INF, INF, 0]
]
floydWarshall(graph);