I want to arrange list of 2d coordinates in a clockwise direction using python. I found similar Q&A here and it is working fine for small scale of data. I had a coordinates list of around 200k points and tried to execute same code but it is unable to execute.
from functools import reduce
import operator
import math
coords = [(1,1),(3,2),...] # Around 200k points
coords = list(dict.fromkeys(coords))
center = tuple(map(operator.truediv, functools.reduce(lambda x, y: map(operator.add, x, y), coords), [len(coords)] * 2))
final_list = (sorted(coords, key=lambda coord: (-135 - math.degrees(math.atan2(*tuple(map(operator.sub, coord, center))[::-1]))) % 360))
In the above code it is failing to calculate center and program exiting automatically. Is the any thing to change for holding and calculate for huge list of coordinates?