<div class="gmail_quote">On Mon, Dec 3, 2012 at 3:17 PM, Peng Yu <span dir="ltr"><<a href="mailto:pengyu.ut@gmail.com" target="_blank">pengyu.ut@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi,<br>
<br>
I'm not able to find the documentation on what locale is used for<br>
sorted() when the 'cmp' argument is not specified. Could anybody let<br>
me what the default is? If I always want LC_ALL=C, do I need to<br>
explicitly set the locale? Or it is the default?<br></blockquote></div><br>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:<br>

<br>"Strings are compared lexicographically using the numeric equivalents (the
result of the built-in function <a class="reference internal" href="http://docs.python.org/3/library/functions.html#ord" title="ord"><tt class="xref py py-func docutils literal"><span class="pre">ord()</span></tt></a>) of their characters."<br>

<br>If you want to sort according to a specific locale, use the locale.strxfrm key function:<br><br>sorted_strings = sorted(original_strings, key=locale.strxfrm)<br>