I am trying to find the quickest way to sort a list. For example, say i was trying to sort the following list
lst = [1, 0, -1, 0.1, 0, 5, 10, 4]
What i want at the end, is to have the sorted list, but to also be able to know what their indexes in lst
were, before the sorting.
The method i am currently using is this
lst = [1, 0, -1, 0.1, 0, 5, 10, 4]
lst = list(enumerate(lst))
lst.sort(key = lambda x: x[1], reverse = True)
Doing so will give lst = [(6, 10), (5, 5), (7, 4), (0, 1), (3, 0.1), (1, 0), (4, 0), (2, -1)]
Now i do not necessarily need to have the tuple (idx, value), it can be two separate lists. The important part, is to sort the values, and also know what were the 'original' indexes in the list lst
. So for example get:
lst_val = [10, 5, 4, 1, 0.1, 0, 0, -1]
lst_idx = [6, 5, 7, 0, 3, 1, 4, 2]
Now i was wondering if there was maybe a quicker/more efficient method to sort this way, because i could have a list with over 200,000 values inside it.
Using numpy
is allowed, but besides that i don't think other modules are allowed.