<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sort(polylines):
 """ sort points within polyline """

    for n, c in enumerate(polylines):
        l = len(c)
        if l > 2:
            # DEFINE FIRST AND LAST INDEX A THOSE TWO POINTS THAT
            # HAVE THE BIGGEST DIFFERENCE FROM A MIDDLE:
            mid = c.mean(axis=0)

            distV = (c - mid)
            dists = norm(distV, axis=-1)

            firstI = np.argmax(dists)
            sign = np.sign(distV[firstI])

            dd = np.logical_or(np.sign(distV[:, 0]) != sign[0],
                               np.sign(distV[:, 1]) != sign[1])

            dists[~dd] = 0
            lastI = np.argmax(dists)

            ind = _sort(c, firstI, lastI)
            c = c[ind]
            polylines[n] = c