[Tutor] Lexicographic ordering (or something simpler)

Kent Johnson kent37 at tds.net
Wed Mar 14 00:58:05 CET 2007


Matt Williams wrote:
> Dear All,
> 
> I'm trying to write something to calculate rule priorities, based on 
> their provenance (ultimately I'm after a lexicographic ordering)

I don't understand your problem description at all but maybe this will 
help. If you sort a list of lists or a list of tuples it will be a 
lexicographical sort. And the sort() method takes an optional key= 
parameter which is a function that creates a sort key. So if you can 
create a key off your terms then you can sort off that.
> 
> I have a set of terms (the provenances) I'm try to sort. I've done it by 
> associating each possible set of terms with a dictionary, and then using 
> the elements of the set as keys of the dictionary, so that it can look 
> up the values. This is (almost certainly) sub-optimal, but ok for now....

If you have some working code it would probably be helpful to see it. 
Then we can help you improve it.

Kent


More information about the Tutor mailing list