I tried to change a pair in a vertex from the loop in "setEdge" function but failed.
Is there another way to change the value of the pair?
I’m pretty new to python so maybe it’s a little stupid question
class Vertex: def __init__(self,id): self.id = id self.neighbors =  def addNeighbor(self, v, w=0): self.neighbors.append((v,w)) def setEdge(self, frm, to, w): if frm not in self.vertexes: self.addVertex(frm) if to not in self.vertexes: self.addVertex(to) for v in self.vertexes: if v == frm: for t in v.neighbors: if t == to: newWeight = t + w t = (to, newWeight) break v.addNeighbor(to, w)
problem here – not changing t value:
if t == to: newWeight = t + w t = (to, newWeight) break
Thank’s a lot
Source: Python Questions