On Mon, Jul 23, 2012 at 5:40 PM, Alan Gauld <alan.ga...@btinternet.com>wrote:
> > create a sorted copy > > L1 = [...original data...] > L2 = sorted(L1) > > Now you can compare indexes except if there are duplicate elements > and you need to know which specific copy is where. In that case > I think you need to use id() but even that fails for small ints and other > cached values. > > If the data is too large to hold two copies you could create a list > of tuples with the original indexes: > > L2 = [] > n = -1 > while L1: > L2.append( (n,L1.pop()) ) > n -= 1 > > This creates L2 with a reversed L1 using the negative index of the > original list. A bit clunky, I'm sure there is a neater way but it seems to > work. But hopefully memory is not so tight you need to do this! > sort_index = numpy.argsort(L1) solves it, and does not need such Mumbo-Jumping!
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor