Custom sorting (including digraphs)

Peter Clark pc451 at
Thu Mar 13 01:16:53 CET 2003

I'm creating a dictionary creation program (as in lexicons, not
hashes) and have run into a small problem: I would like to implement
customizable sorting, which would include the ability to sort multiple
characters as one. For example:

order = "a, b, c, ch, d, e, (etc)"

would sort "cat, celery, cherry" as "cat, cherry, celery". In other
words, all occurances of "ch" would be sorted as following "c".
Naturally, this also needs to be able to take Unicode data into
account (which I think wouldn't be a problem, but you never know), be
able to scale upwards to trigraphs ("thl" for example) and quadgraphs
("shch"), as well as be as speedy as possible, since I expect to be
using it to  alphabetize several thousand entries.

I've looked over at the Cookbook, and while it has some nice recipes
for custom sorting, but none take into consideration treating multiple
characters as a single unit. TIA,


More information about the Python-list mailing list