I have a list of points, where each point is d-dimensional. The list is currently sorted with the regular list.sort()
function, which means the keys are prioritized from the first dimension to the last in order.
I want to take the list and sort it while prioritizing the 2nd key, running a code on it, then prioritizing the 3nd key and so on.
Is there a more efficient way than just using the sort() function with a specific key?
Because I know the points are sorted at each step with priority to the k-th dimension and I want to sort it by the next one, so I think it might be possible to manage the list and sort it just like combining a bunch of sorted lists in O(n) instead of O(nlogn) for the regular sort()
. Is it possible, or am I mistaken?
If possible, a help with implementation in python would be appreciated.
Edit:
Example of a list after the list.sort()
function:
[(-3, -5, -5, -2), (-3, -4, 2, -2), (-3, 2, 5, 2), (0, 0, -5, 1), (1, -3, 2, 0), (2, -1, 0, 0), (2, 3, -1, 0), (4, 1, -2, 1), (5, -3, -1, 1), (5, 1, -2, -2)]