<html>
<head>
</head>
<body class='hmmessage'><div dir='ltr'>


<div dir="ltr">

<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style>
<div dir="ltr"><a href="https://docs.python.org/3.4/library/functions.html?highlight=sorted#sorted">sorted() documentation</a> states: <br><br>"The built-in <a class="reference internal" href="https://docs.python.org/3.4/library/functions.html?highlight=sorted#sorted" title="sorted"><tt class="xref py py-func docutils literal"><span class="pre"><span class="highlighted">sorted</span>()</span></tt></a> function is guaranteed to be stable. A sort is
stable if it guarantees not to change the relative order of elements that
compare equal — this is helpful for sorting in multiple passes (for
example, sort by department, then by salary grade). "<br><br>Some people might get the misconception that order will be stable even on different runs of the exact same code. <br><br>e.g.  the code below: <br><br><pre style="" class="lang-py prettyprint prettyprinted"><code><span class="pln">d </span><span class="pun">=</span><span class="pln"> </span><span class="pun">{</span><span class="str">'a'</span><span class="pun">:</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="str">'b'</span><span class="pun">:</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="str">'c'</span><span class="pun">:</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="str">'d'</span><span class="pun">:</span><span class="pln"> </span><span class="lit">1</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">print</span><span class="pun">(</span><span class="pln">sorted</span><span class="pun">(</span><span class="pln">d</span><span class="pun">,</span><span class="pln"> key</span><span class="pun">=</span><span class="kwd">lambda</span><span class="pln"> x</span><span class="pun">:</span><span class="pln"> d</span><span class="pun">[</span><span class="pln">x</span><span style="" class="pun">]))<br><br><font style="font-size: 12pt;" size="3"># It would print</font><font style="font-size: 12pt;" size="3"> a different order on different runs (assuming PYTHONHASHSEED=random).</font><font style="font-size: 12pt;" size="3"><br></font><font style="font-size: 10pt;" size="2"></font><br></span></code></pre>For more details see <a href="http://stackoverflow.com/q/32548198/4230591">this StackOverflow question</a>. <br><br>Perhaps adding the following in the documentation might help: <br><br>"It is not guaranteed to be stable on different runs  or when the order of the given iterable has changed (even if the iterable is a dict)."<br><br><br></div>
</div>
                                          </div></body>
</html>