bugfix: graph conversion, append after key creation
This commit is contained in:
parent
bb87ac70f5
commit
d04a34d266
1 changed files with 4 additions and 2 deletions
6
graph.py
6
graph.py
|
|
@ -2,7 +2,9 @@
|
||||||
def graph( segments ):
|
def graph( segments ):
|
||||||
graph = {}
|
graph = {}
|
||||||
for start,end in segments:
|
for start,end in segments:
|
||||||
graph[start] = graph.get( start, [] ).append( end )
|
graph[start] = graph.get( start, [] )
|
||||||
graph[end] = graph.get( end, [] ).append( start )
|
graph[start].append( end )
|
||||||
|
graph[end] = graph.get( end, [] )
|
||||||
|
graph[end].append( start )
|
||||||
return graph
|
return graph
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue