[Tutor] Sorting a list in an add order
Matt Williams
matthew.williams at cancer.org.uk
Wed Sep 6 12:03:39 CEST 2006
Dear List,
I've written a small script to extract the definitions from my thesis,
and output them as a .tex file, which works ok but I have a small problem.
The input is done by specifying a directory, and using glob to find the
".tex" filenames.
However, I want to process them so that they are arranged in the correct
order, which means I need to sort the list of files. Of course, because
they aren't named in any (obvious) order, I'm a bit stuck.
I thought about using a dictionary to map names and order: so {"OAF":1,
"Valuation":2...etc}, but I don't don't know how to take it on from
here. I was thinking of looking up the filename in the dictionary (using
.startswith() to get some basic rough-matching capacity) and then using
that to return the order that the files should be handled in.
Any comments/ better ideas?
Thanks,
Matt
More information about the Tutor
mailing list