distances = { "u":0,
"v":0,
"w":0,
"x":0,
"y":0,
"z":0 }
Np = ["u"]
nodes = ["u","v","w","x","y","z"]
max = 20;
for node in nodes:
if (node+"-u") in dictionary:
distances[node] = dictionary["u-"+node]
else:
distances[node] = max;
while Np != nodes:
for node in nodes:
if node not in Np:
if (distances[node] < max):
min = distances[node]
minnode = node;
max = min;
Np.append(minnode);
print(Np);
for node in nodes:
if node not in Np:
if (node+"-"+minnode) in dictionary:
distances[node] = min(distances[node], distances[minnode] + dictionary[node+"-"+minnode]);
please help where i am going wrong, i am getting error at last line of code:
distances[node] = min(distances[node], distances[minnode] + dictionary[node+"-"+minnode]);
it is saying that i am doing typeError of 'int' but i traced code back to start, i can't see what is wrong. I am using dictionary object and list object, maybe that is the cause? please look at code and mend
min = distances[node]
minnode = node;
max = min;
From there we know that the min
is a variable of a number or something, but you use it as a function in your last line of code.
distances[node] = min(distances[node], distances[minnode] + dictionary[node+"-"+minnode]);
Try using another name for your variable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.