>>> a = [1,4,6,2,3] >>> [b[0] for b in sorted(enumerate(a),key=lambda i:i[1])] [0, 3, 4, 1, 2]
Explanation:
enumerate(a) returns an enumeration by tuples consisting of indices and values in the original list: [(0, 1), (1, 4), (2, 6), (3, 2), (4, 3)]
Then sorted with key from lambda i:i[1] sorts based on the original values (element 1 of each tuple).
Finally, understanding the list [b[0] for b in ... ] returns the original indexes (element 0 of each tuple).
source share