Sem4SE/04/test
2026-05-21 14:52:47 +02:00

50 lines
1.1 KiB
Plaintext
Executable File

connections = [('Würzburg', 'Schweinfurt', 50),
('Würzburg', 'Nürnberg', 100),
('Schweinfurt', 'Bamberg', 60),
('Bamberg', 'Coburg', 50),
('Bamberg', 'Nürnberg', 60),
('Bamberg', 'Bayreuth', 60),
('Nürnberg', 'Bayreuth', 90),
('Bayreuth', 'Hof', 50),
('Coburg', 'Hof', 80),
]
def allNodes(connections):
nodes = set()
for a in connections:
nodes.add(a[0])
nodes.add(a[1])
return nodes
def initMap(connections):
m = allNodes(connections)
knoten = {}
for a in m:
knoten[a] = {}
return knoten
def addConnection(data, connection):
a, b, c = connection
data[a].setdefault('connection', []).append([b, c])
data[b].setdefault('connection', []).append([a, c])
return data
map = initMap(connections)
print(initMap(connections))
print(connections[0][0])
for con in connections:
addConnection(map, con)
print(map)