Need customised sort

bvdpoel at uniserve.com bvdpoel at uniserve.com
Sat Apr 13 15:19:35 EDT 2002


Yeah, I thought this would be easy...

I have a list like this:

	[ [0, x, [0, y, [4, n] ...]

and I want to sort it a bit. The sort should only work on the first
element AND, retain the order of list elements if 2 adjacent elements
have identical first elements. So, in the above example, if x > y I
still want the list to be sorted with the x first (as passed).

Hope this makes sense and someone has a quick and dirty solution.

Oh, maybe this will help explain... I'm doing some midi work and the
list represents a list of midi events. The first element is an offset
into the track (not a delta midi) and the second is the midi event. If I
just use a builtin sort() my '0' events tend to move around, depending
on the 'event'....and this can cause problems. Example, I might want to
do a program change and a note on event at 0. I and to my list in the
right order, but I don't want the sort to move the note event in front
of the program change (mind you, I'm not sure if matters for the midi
sequencer...). The reason for the sort in the first place is that some
note events might get placed in the wrong order (a note off event for,
say 1999, might get placed after a note on for 1888).

Thanks.



-- 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bvdpoel at uniserve.com
WWW:   http://users.uniserve.com/~bvdpoel




More information about the Python-list mailing list