See Python Unicode Collation Algorithm for background.
This version fixes a major bug that prevented the collation algorithm from working properly with any expansions:
UPDATE (2012-06-21): Now see https://github.com/jtauber/pyuca
originally published on jtauber.com