<div dir="ltr">On Thu, Aug 7, 2008 at 12:42 AM, Shrutarshi Basu <span dir="ltr">&lt;<a href="mailto:technorapture@gmail.com">technorapture@gmail.com</a>&gt;</span> wrote:<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;">
If you&#39;re just going to be using numbers as dictionary keys, it might<br>
be simpler just to use a list structure. Dictionaries don&#39;t preserve<br>
order, so you&#39;d need to write extra code if you ever need to iterate<br>
over it in order.</blockquote><div><br></div></div>It wouldn&#39;t be any (or at least much) more difficult than looping over a list of known/unknown length.<br><br>Known length:<br><br>for x in range(0, length):<br>&nbsp;&nbsp;&nbsp; do something with mydict[x]<br>
<br><br><br>Unknown length, dict keys starting at 0:<br><br>for x in range(0, len(mydict)):<br>&nbsp;&nbsp;&nbsp; do something with mydict[x]<br><br><br><br>Known length, dict keys starting at 1:<br><br>for x in range(1, (len(mydict)+1)):<br>
&nbsp;&nbsp;&nbsp; do something with mydict[x]<br><br><br><br>Probably not the most elegant solution, but it does work. I can&#39;t really think of a particular reason it would be useful, though. The main reason a dict is useful is for key values that won&#39;t change, and aren&#39;t easily kept track of (i.e. names). It&#39;s a lot more difficult (at least for the interpreter, as in processor cycles) to find &quot;John Smith&quot; in a list, than to convert it to a hash value and look it up in a hash table.<br>
<br>HTH,<br>Wayne<br>
</div>