[Tutor] Original indices after Sorting
Ali Torkamani
torkamani at gmail.com
Mon Jul 23 21:55:49 CEST 2012
Hi every one,
How can we get the indices of values in the original list after sorting a
list?
for example:
(Pdb) A=[ 1, -1, 0, 7, 9, 1.3, 2.9 ]
(Pdb) A.sort()
(Pdb) A
[-1, 0, 1, 1.3, 2.9, 7, 9]
(Pdb)
Now I want to have the original indices of the sorted list, i.e:
[1, 2, 0, 5, 6, 3, 4]
If you know Matlab, in Matlab you'll write:
[B,L] = sort(A)
Then L, is what I'm refering to.
A
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120723/fced2627/attachment.html>
More information about the Tutor
mailing list