Sort()

Turhan Ozen txo at cs.nott.ac.uk
Thu Jun 5 12:32:06 EDT 2003


I created a class and modified the default _comp_  function.  I can sort 
an array of instances of this class. But I don't want to change the 
original array. Instead, I want to keep the positions after sorting in 
an attribute of the instances.

Instead of [a1,a2,a3] becoming [a2,a1,a3], I would like the order remain 
same but

a1.rank=2
a2.rank=1
a3.rank=3

How can I do this? Does this functionality already exist? If not could 
you please give me advice on how to implement it? I have read the HOWTO 
on sorting, there is an example of sorting classes there. Is there any 
other place where I can find more examples of using Python functions?

Thanks,
Turhan.





More information about the Python-list mailing list