[Tutor] Original indices after Sorting
Ali Torkamani
torkamani at gmail.com
Mon Jul 23 22:02:37 CEST 2012
By the way, I myself, have this solution:
How can we get the indices of values in the original list after sorting a
> list?
>
>
(Pdb) A=[ 1, -1, 0, 7, 9, 1.3, 2.9 ]
(Pdb) sorted(zip(A, range(len(A))), key = lambda x: x[0])
[(-1, 1), (0, 2), (1, 0), (1.3, 5), (2.9, 6), (7, 3), (9, 4)]
But compared to what Matlab neatly does, it's too ugly:
> If you know Matlab, in Matlab you'll write:
>
> [B,L] = sort(A)
>
>
A
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120723/e6a74969/attachment.html>
More information about the Tutor
mailing list