On Mon, Dec 3, 2012 at 3:17 PM, Peng Yu <pengyu...@gmail.com> wrote: > Hi, > > I'm not able to find the documentation on what locale is used for > sorted() when the 'cmp' argument is not specified. Could anybody let > me what the default is? If I always want LC_ALL=C, do I need to > explicitly set the locale? Or it is the default? >
The default is that a sorts before b if a < b. So what you actually want to know is how strings compare to one another, and the answer from the Python 3 documentation is: "Strings are compared lexicographically using the numeric equivalents (the result of the built-in function ord()<http://docs.python.org/3/library/functions.html#ord>) of their characters." If you want to sort according to a specific locale, use the locale.strxfrm key function: sorted_strings = sorted(original_strings, key=locale.strxfrm)
-- http://mail.python.org/mailman/listinfo/python-list