[Tutor] Sorting against another list

alan.gauld@bt.com alan.gauld@bt.com
Mon, 25 Jun 2001 10:56:37 +0100


This idea is untested but seems like it should work!

> [ 'aa', 'qq', 'ttt', 'hh']  # master list

Convert list to dictionary keyed by item and valued by 
list index

ie: 
master = {'aa':0,'qq':1...'hh':3}

Now write a cmp() function that checks the index of your list 
items against the dictionary index value.

Something like:

def cmp(a,b):
   return master[a] - master[b]

I think....

Alan G.