<br><div class="gmail_quote">On Tue, Aug 2, 2011 at 5:53 PM, Chris Rebert <span dir="ltr"><<a href="mailto:clp2@rebertia.com">clp2@rebertia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im">On Tue, Aug 2, 2011 at 11:02 AM, smith jack <<a href="mailto:thinke365@gmail.com">thinke365@gmail.com</a>> wrote:<br>
> the source code is as follows<br>
><br>
> x={}<br>
> x['a'] = 11<br>
> x['c'] = 19<br>
> x['b'] = 13<br>
> print x<br></div>
<br>
If you /really/ need a sorted mapping datatype, google for<br>
"sorteddict" (which is quite distinct from OrderedDict).<br>
Or look for a binary search tree or skip list implementation of some<br>
sort; but these aren't commonly used in Python, so it may be hard to<br>
find a good one.<br></blockquote><div><br>I've found a need for such a thing a couple of times.<br><br>Anyway, here are some other possibilities:<br><br><a href="http://stromberg.dnsalias.org/~dstromberg/treap/">http://stromberg.dnsalias.org/~dstromberg/treap/</a><br>
<a href="http://pypi.python.org/pypi/bintrees/0.3.0">http://pypi.python.org/pypi/bintrees/0.3.0</a><br><br>The treap code is considered by its author (me) production-quality, has an extensive test suite, and is known to work on CPython 2.x, CPython 3.x, PyPy and Jython.  The CPython's can optionally be sped up with a Cython variant of the same code (autogenerated from a single source file using m4), and while I test on all 4 regularly, lately I mostly run it in production using the pure python version on PyPy.<br>
<br>EG:<br><br>$ python<br>Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)<br>[GCC 4.4.5] on linux2<br>Type "help", "copyright", "credits" or "license" for more information.<br>>>> import treap<br>
>>> t = treap.treap()<br>>>> import random<br>>>> for i in xrange(10):<br>...    t[random.random()] = random.random()<br>...<br>>>> print list(t.items())<br>[(0.049542221325585611, 0.60627903220498502), (0.26787423324282511, 0.95374362416785075), (0.45599886628328978, 0.57612454878587427), (0.46375501394309371, 0.28130836755784228), (0.54144253493651362, 0.47941229743653202), (0.54584770558330997, 0.49062231291462766), (0.5592476615748635, 0.39138521009523863), (0.73976131715214732, 0.99783565376628391), (0.7638117918732078, 0.55600393733208187), (0.88094790991949967, 0.90033960217787801)]<br>
>>><br><br></div></div>