그래프의 다음 구현에서 v, w = e
할당은 무엇을하고 어떻게 작동합니까? 우리는 그런 비대칭적인 임무를 수행 할 수 없다고 생각했습니다.파이썬 그래프 (초보자)에 가장자리 추가하기
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]' –