1 # Collation algorithms for Python
2 -------------------------------------------
4 pycollate is an interface to various collation algorithms for Python.
7 - `icu` - Based on the IBM ICU toolkit and Jim Fulton's zope.ucol.
8 - `syslocale` - Native OS collation routines.
9 - `codepoint` - Raw Unicode codepoint comparison
11 If available, you'll probably want to use the ICU backend. If it's not
12 available, syslocale should work on most Python installations. A
13 specific backend can be used, or a "best" backend is chosen by
16 pycollate also provides tools to perform word-wise and numeric sorts.
18 pycollate, as with all Unicode collation tools, is a work in progress.
22 $ sudo apt-get install python-pyrex libicu-dev
24 $ sudo ./setup.py install
29 strings = open("contents.txt").read().decode("utf-8").splitlines()
30 strings.sort(key=collate.key)
36 Collation is the process of sorting information in a useful way. In
37 particular, this module sorts strings in a way that humans might
40 ### What's so hard about that?
42 Nothing, if your strings are all in one language and you speak English
45 On the other hand, if that's not the case you need to make sure "ss"
46 and "ß" sort similarly, "å" sorts like "A" (unless you're Swedish),
47 and "21 Monkeys" comes after "3 Monkeys".
49 ### How fast is the library?
51 Slow enough that you will probably want to cache sort keys. On a
52 mid-range system at the time of its writing, it takes about half a
53 second to sort 10000 song titles.
60 Copyright (c) 2004 Zope Corporation and Contributors.
63 This software is subject to the provisions of the Zope Public License,
64 Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
65 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
66 WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
67 WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
68 FOR A PARTICULAR PURPOSE.
72 Copyright 2010 Joe Wreschnig
74 Permission is hereby granted, free of charge, to any person obtaining a copy
75 of this software and associated documentation files (the "Software"), to deal
76 in the Software without restriction, including without limitation the rights
77 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
78 copies of the Software, and to permit persons to whom the Software is
79 furnished to do so, subject to the following conditions:
81 The above copyright notice and this permission notice shall be included in
82 all copies or substantial portions of the Software.
84 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
85 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
86 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
87 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
88 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
89 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN