defn noob a écrit :
class Graph(object):
where does anyone write like that?
Almost everywhere nowadays.
I've seen only examples like i have
written.
Most of the doc has still not been updated since the introduction of
newstyle classes years ago. You'll find more here:
klant a écrit :
do i need to call Graph.find_path?
g = Graph({'A': ['B', 'C'],
'B': ['C', 'D'],
'C': ['D'],
'D': ['C'],
'E': ['F'],
'F': ['C']})
g
__main__.Graph instance at 0x01D74378
g.find_all_paths('A', 'C')
class Graph(object):
where does anyone write like that? I've seen only examples like i have
written.
is the object then passed to init?
class Graph(object):
def __init__(self, dictionary):
self.structure = dictionary
or
class Graph(object):
def __init__(self, object):
if start == end:
return path
if not self.dictionary.has_key(start):
if start not in self.dictionnary:
return None
for node in self.dictionary[start]:
if node not in path:
newpath =
defn noob wrote:
if start == end:
return path
if not self.dictionary.has_key(start):
if start not in self.dictionnary:
return None
for node in self.dictionary[start]:
if node not in path:
newpath =
do i need to call Graph.find_path?
g = Graph({'A': ['B', 'C'],
'B': ['C', 'D'],
'C': ['D'],
'D': ['C'],
'E': ['F'],
'F': ['C']})
g
__main__.Graph instance at 0x01D74378
g.find_all_paths('A', 'C')
Traceback (most recent call
Wrong:
newpath = find_path(self.dictionary, node, end, path)
newpaths = find_all_paths(self.dictionary, node, end, path)
newpath = find_shortest_path(self.dictionary, node, end, path)
Correct;
newpath = self.find_path(self.dictionary, node, end, path)
newpaths =