def distance(a, b):
    return sum((xa - xb) ** 2 for xa, xb in zip(a, b))

def clusters(sources, demands):
    result = dict((source, []) for source in sources)
for demand in demands:
    nearest = min(sources, key=lambda s: distance(s, demand))
result[nearest].append(demand)
return result
Тесселяция Вороного в Python