<br><br><div><span class="gmail_quote">On 9/4/07, <b class="gmail_sendername">"Martin v. L÷wis"</b> <<a href="mailto:email@example.com">firstname.lastname@example.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> (assuming d[x] is O(log n))<br><br>In Python, d[x] is typically considered to be O(1) (unlike in C++,<br>where it is O(log n)). Of course, with Python using a hashtable,<br>performance may decrease in the presence of collisions. In the
<br>normal case, dict((x, d[x]) for x in d) will be O(n) in Python.</blockquote><div><br>And if the speed of d[x] were ever an issue that shows up on python performance profiles when used in a loop like that it would be pretty easy to optimize the common case internally by having the key iteration retain an optional (weak?) reference in the dict object to the most recently looked up key+value for a short circuit quickly returning its value. I do not expect that to ever to matter as code can just loop using the appropriate iterator instead.