1
在以下图形实现中,v, w = e
分配的作用是什么?它如何工作?我认为我们不允许做这样的不对称任务。在Python图形中添加边缘(初学者)
class Graph(dict):
def __init__(self, vs=[], es=[]):
"""create a new graph. (vs) is a list of vertices;
(es) is a list of edges."""
for v in vs:
self.add_vertex(v)
for e in es:
self.add_edge(e)
def add_vertex(self, v):
"""add (v) to the graph"""
self[v] = {}
def add_edge(self, e):
"""add (e) to the graph by adding an entry in both directions.
If there is already an edge connecting these Vertices, the
new edge replaces it.
"""
v, w = e
self[v][w] = e
self[w][v] = e
它被称为“解包” - 例如'a,b = [1,2]' – 2013-02-22 21:07:51