some cleanup
diff --git a/sim.py b/sim.py --- a/sim.py +++ b/sim.py @@ -178,12 +178,18 @@ def fold(net, num=100): checkfold(target, prev, net) return routelengths +def distances(target, nodelist): + """calculate the distances between the target and the given list of nodes.""" + lengths = [] + for n in nodelist: + lengths.append(dist(n,target)) + return lengths + def linklengths(net): """calculate the lengths of all links""" lengths = [] for node, targets in net.items(): - for t in targets: - lengths.append(dist(t, node)) + lengths.extend(distances(node, targets)) return lengths if __name__ == "__main__":