On 29 Jul., 01:05, Raymond Hettinger <[EMAIL PROTECTED]> wrote: > [Ervan Ensis] > > > I have a list like [108, 58, 68]. I want to return > > the sorted indices of these items in the same order > > as the original list. So I should return [2, 0, 1] > > One solution is to think of the list indexes > being sorted according the their corresponding > values in the input array: > > >>> s = [ 108, 58, 68 ] > >>> sorted(range(len(s)), key=s.__getitem__) > > [1, 2, 0] >
To get the desired output you have to apply it twice: >>> sorted(range(len(s)), key=sorted(range(len(s)), >>> key=s.__getitem__).__getitem__) [2, 0, 1] Wolfram -- http://mail.python.org/mailman/listinfo/python-list