<div class="gmail_quote">On Mon, Feb 22, 2010 at 10:32 AM, Bryan <span dir="ltr"><<a href="mailto:bryanvick@gmail.com">bryanvick@gmail.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;">
unorderedDict = {}<br>
for thing in unorderedList:<br>
if <a href="http://thing.id" target="_blank">thing.id</a> in unorderedDict:<br>
UpdateExistingValue(unorderedDict[<a href="http://thing.id" target="_blank">thing.id</a>])<br>
else:<br>
CreateNewValue(unorderedDict[<a href="http://thing.id" target="_blank">thing.id</a>])<br>
<br>
orderedDict = OrderedDict()<br>
for k in sorted(unorderedDict.keys()):<br>
orderedDict[k] unorderedDict.pop(k)<font color="#888888"><br></font></blockquote><div><br>It's not entirely clear what UpdateExistingValue and CreateNewValue do. However, it looks like you are trying to create a dictionary where the keys are sorted. Is that right?<br>
<br>If so, you could use the sorteddict type from my blist package, which is similar to an OrderDict except it efficiently keeps the keys in sorted order instead of insertion order. For example:<br><br>>>> from blist import sorteddict<br>
>>> my_dict = sorteddict({1: 'a', 6: 'b', -5: 'c'})<br>>>> my_dict.keys()<br>[-5, 1, 6]<br>>>> my_dict[2] = 'd'<br>>>> my_dict.keys()<br>[-5, 1, 2, 6]<br>
<br>It's available here:<br><a href="http://pypi.python.org/pypi/blist/">http://pypi.python.org/pypi/blist/</a><br></div></div><div style="margin: 2em 0pt;" name="sig_2341e11ee1">--<br>
Daniel Stutzbach, Ph.D.<br>
President, <a href="http://stutzbachenterprises.com">Stutzbach Enterprises, LLC</a>
</div><br>