A Python sort trick
By chys on October 23rd, 2009>>> a = [12,14,133,130,176,25,54,79,127] >>> b = sorted(range(len(a)),key=a.__getitem__) >>> b [0, 1, 5, 6, 7, 8, 3, 2, 4] >>> map(a.__getitem__,b) [12, 14, 25, 54, 79, 127, 130, 133, 176]
b is the so called sort index.
Reference
http://www.newsmth.net/bbscon.php?bid=284&id=59819
No related posts.
Tags: Python
Leave a Reply
Hint: Register at Gravatar and your comments will be accompanied by your personalized icon.
