<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">But my point is that we we need to focus on finding real use cases and<br>

exploring how best to solve them. &nbsp;Otherwise we might as well throw in<br>
my OrderedSet[1] as-is, despite that it&#39;s got no comments and no<br>
ratings. &nbsp;Even I don&#39;t seem to use it.<br>
</blockquote><div><br>I&#39;m mostly lurking on these threads, so as to be semi-prepared when new versions come out.. in fifty years, since we *just* migrated from 2.3 to 2.4 on our product, so. :)<br><br>Anyways, we&#39;ve had an OrderedDictionary sort of implementation in our library for eons. The product is commercial and a mix between a desktop application and a web one, with an application server and cross-platform availability... so there&#39;s a slightly bizarre and wide range of uses that we&#39;ve found for putting ordered dictionaries to. If some various use-cases and our reasoning helps, here it is. If not, ignore :)<br>
<br>- One is that the system is modular, with various parts able to be activated or deactivated in configuration. The order of module load is important, as we&#39;ve never quite bothered to put in automatic dependency checking -- that&#39;s just overboard for us. Further, the modules can&#39;t really be referred to each other via &quot;import&quot; or in code, but instead need to go through a layer of indirection through a name-- so-- the system maintains an ordered dict of modules, a la sys.modules, with the order determining load when it goes through to initialize itself.<br>
<br>- There&#39;s several more places with a similar pattern; a mapping between &quot;Component Name&quot; and &quot;Module&quot; for generic systems. A processing host which is meant to be able to load and run any kind of service or task.<br>
<br>- There&#39;s several places where a user is configuring a slightly complex set of actions-- he gives these actions a name, which is shown to the user, and then we have the configuration options itself we use if that is chosen. Its just natural/easy to store that in an ordered dict after we pull it out of the DB, as we want its order to be whatever the user chooses in their setup, and the key-&gt;value association is clear.<br>
<br>- In a modular application with a generic outer interface(meaning the main app can&#39;t even fathom what all it might be asked to load), there&#39;s things like a &quot;Windows&quot; menu item that&#39;s easily stored internally as a mapping between window names and the window object itself, so the menu can be readily re-generated at will and the window found to switch to.<br>
<br>- In fact, we use a lot of OrderedDictionaries as a part of that UI to data/configuration mapping, come to think of it. We know the order of &quot;fields&quot; that someone can search on in the database in advance, and have them written into the searchUI code as an ordered dict because it just works nicely. The keys() become a drop-down list, the value a structure identifying to the central server what field it is they&#39;re searching on.<br>
<br>- Fiiinally (sorta), we find passing ordered dictionaries to our Genshi web templating layer very lovely for making easy-designable web templates for the web client. We even let customers edit them sometimes! <br><br>
Basically, after looking at all of these, my impressions of an &quot;ordered dictionary&quot; for the various use cases we use are:<br><br>- The ordered dictionary is used almost exclusively in situations where we are getting the order implicitly from some other source. Be it a SQL query (with its own ORDER BY statements), a configuration option, the order of lines in a file, an auto-sequenced table, or hard-coded data.... Thus, we&#39;ve always found &quot;insertion order&quot; to be important.<br>
<br>- Much to my surprise, we actually aren&#39;t ever using an ordered dictionary in a situation where the value ends up being modified after the dictionary is loaded.<br><br>- The only time we use dictionaries where we are updating them after the fact and their order is -expected- to change is when we are using a *sorted* dictionary. <br>
<br>- As such, I&#39;d be quite surprised if I was updating the value of an ordered dictionary and it were to change its order. Meaning:<br><br>&nbsp; &gt;&gt;&gt; d = odict()<br>&nbsp; &gt;&gt;&gt; d[&quot;hello&quot;] = 1<br>&nbsp; &gt;&gt;&gt; d[&quot;there&quot;] = 2<br>
&nbsp; &gt;&gt;&gt; d[&quot;hello&quot;] = 3<br>&nbsp; &gt;&gt;&gt; d.keys()<br>&nbsp; [&#39;hello&#39;, &#39;there&#39;]<br><br>And not: [&#39;there&#39;, &#39;hello&#39;]<br><br>An ordered dictionary that does not simply preserve initial insertion order strikes me as a *sorted* dictionary-- sorting on insertion time. I&#39;d expect a sorted dictionary to shift itself around as appropriate. I&#39;d not expect an ordered dictionary to change the order without some explicit action.<br>
<br>To me, &quot;ordered dictionary&quot; is in fact a *preordered* dictionary. The order is defined before the data in, and the dictionary&#39;s job is to just preserve it.<br><br>Anyways. No idea if that&#39;ll help the discussion, but a couple people kept talking about use cases :)<br>
<br>--Stephen<br>P.S. Our implementation, incidentally, is essentially the same as one mentioned above though its subclassing from UserDict (historical reasons for now). We just track the keys in _keys, and if someone&#39;s setting something in the dictionary not in keys, we append. It seemed the most natural/obvious way to do it.<br>
</div></div>