Sorting a list to by another's order

Graeme Longman glongman at ilangua.com
Fri Aug 30 09:22:42 EDT 2002


Hi,

I have two lists:

listA = ['d', 'c', 'f', 'a', 'b', 'e']
listB = ['a', 'c', 'd', 'f']

I need to sort listA so that it's order corresponds to that of listB (if
the item in listA isn't in listB then it should be at the end of the
list)

Is there a quick way to do this using sort() instead of writng a bunch
of for loops and if-else statements ?

Thanks very much.
Graeme





More information about the Python-list mailing list