Need customised sort
Terry Reedy
tejarex at yahoo.com
Sat Apr 13 16:55:18 EDT 2002
<bvdpoel at uniserve.com> wrote in message
news:3CB884C7.EE7E04D at uniserve.com...
> I have a list like this:
>
> [ [0, x, [0, y, [4, n] ...]
I am assuming that you mean like this:
[ [0,x], [0,y], [4,n], ...]
If so, it is *possible* that the built in [].sort(cmpfunc) will work
for you *if* you supply the optional custom compare function cmpfunc()
such as:
def mycompare(a,b): return cmp(a[0],b[0])
However, read the reference manual for the Python version you are
using and test. I believe (but may be wrong) that .sort() is now
order preserving but was not always. If not, you will have to find
one or devise a hack to make the sort keys unique. I believe that one
of a[0]<b[0] or a[0]<=b[0] may work, but again check specific
reference.
Terry J. Reedy
More information about the Python-list
mailing list