1import sqlite3 2 3def collate_reverse(string1, string2): 4 return -cmp(string1, string2) 5 6con = sqlite3.connect(":memory:") 7con.create_collation("reverse", collate_reverse) 8 9cur = con.cursor() 10cur.execute("create table test(x)") 11cur.executemany("insert into test(x) values (?)", [("a",), ("b",)]) 12cur.execute("select x from test order by x collate reverse") 13for row in cur: 14 print row 15con.close() 16