import itertools as it
import math

def dist(x, y):
    return math.hypot(y[0] - x[0], y[1] - x[1])
paths = [p for p in it.permutations([(1, 2), (2, 3), (5, 6), (3, 4)])]
path_distances = [sum(map(lambda x: dist(x[0], x[1]), zip(p[:-1], p[1:]))) for
    p in paths]
min_index = argmin(path_distances)
print(paths[min_index], path_distances[min_index])
Rearrange a list of points to reach the shortest distance between them