data[(1, 2), (3, 4), ...]
cur = 0
path = [cur]
totalDist = 0
for i in range(1, len(data)):
    dists = [(dist(data[i], p), pi) for pi, p in enumerate(data) if pi != i and
        pi not in path]
nextDist, cur = min(dists)
totalDist += nextDist
path.append(cur)
print(path, totalDist)
Rearrange a list of points to reach the shortest distance between them