[Python-3000] Default dict iterator should have been iteritems() (original) (raw)
Gregory P. Smith greg at krypto.org
Tue Sep 4 19:11:14 CEST 2007
- Previous message: [Python-3000] Default dict iterator should have been iteritems()
- Next message: [Python-3000] Default dict iterator should have been iteritems()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 9/4/07, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> (assuming d[x] is O(log n)) In Python, d[x] is typically considered to be O(1) (unlike in C++, where it is O(log n)). Of course, with Python using a hashtable, performance may decrease in the presence of collisions. In the normal case, dict((x, d[x]) for x in d) will be O(n) in Python.
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.
-gps -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-3000/attachments/20070904/cbe5ee88/attachment.htm
- Previous message: [Python-3000] Default dict iterator should have been iteritems()
- Next message: [Python-3000] Default dict iterator should have been iteritems()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]