<p dir="ltr">+1</p>
<p dir="ltr">Don't forget values and keys in addition to items.  They aren't as common but come up every so often.  I think you can iterate the keys just by iterating on the dict itself.</p>
<p dir="ltr">Carl</p>
<div class="gmail_quote">On Jun 9, 2015 6:18 PM, "Robert Collins" <<a href="mailto:robertc@robertcollins.net">robertc@robertcollins.net</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm very glad folk are working on Python3 ports.<br>
<br>
I'd like to call attention to one little wart in that process: I get<br>
the feeling that folk are applying a massive regex to find things like<br>
d.iteritems() and convert that to six.iteritems(d).<br>
<br>
I'd very much prefer that such a regex approach move things to<br>
d.items(), which is much easier to read.<br>
<br>
Here's why. Firstly, very very very few of our dict iterations are<br>
going to be performance sensitive in the way that iteritems() matters.<br>
Secondly, no really - unless you're doing HUGE dicts, it doesn't<br>
matter. Thirdly. Really, it doesn't.<br>
<br>
At 1 million items the overhead is 54ms[1]. If we're doing inner loops<br>
on million item dictionaries anywhere in OpenStack today, we have a<br>
problem. We might want to in e.g. the scheduler... if it held<br>
in-memory state on a million hypervisors at once, because I don't<br>
really to to imagine it pulling a million rows from a DB on every<br>
action. But then, we'd be looking at a whole 54ms. I think we could<br>
survive, if we did that (which we don't).<br>
<br>
So - please, no six.iteritems().<br>
<br>
Thanks,<br>
Rob<br>
<br>
<br>
[1]<br>
python2.7 -m timeit -s 'd=dict(enumerate(range(1000000)))' 'for i in<br>
d.items(): pass'<br>
10 loops, best of 3: 76.6 msec per loop<br>
python2.7 -m timeit -s 'd=dict(enumerate(range(1000000)))' 'for i in<br>
d.iteritems(): pass'<br>
100 loops, best of 3: 22.6 msec per loop<br>
python3.4 -m timeit -s 'd=dict(enumerate(range(1000000)))' 'for i in<br>
d.items(): pass'<br>
10 loops, best of 3: 18.9 msec per loop<br>
pypy2.3 -m timeit -s 'd=dict(enumerate(range(1000000)))' 'for i in<br>
d.items(): pass'<br>
10 loops, best of 3: 65.8 msec per loop<br>
# and out of interest, assuming that that hadn't triggered the JIT....<br>
but it had.<br>
 pypy -m timeit -n 1000 -s 'd=dict(enumerate(range(1000000)))' 'for i<br>
in d.items(): pass'<br>
1000 loops, best of 3: 64.3 msec per loop<br>
<br>
--<br>
Robert Collins <<a href="mailto:rbtcollins@hp.com">rbtcollins@hp.com</a>><br>
Distinguished Technologist<br>
HP Converged Cloud<br>
<br>
__________________________________________________________________________<br>
OpenStack Development Mailing List (not for usage questions)<br>
Unsubscribe: <a href="http://OpenStack-dev-request@lists.openstack.org?subject:unsubscribe" target="_blank">OpenStack-dev-request@lists.openstack.org?subject:unsubscribe</a><br>
<a href="http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev" target="_blank">http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev</a><br>
</blockquote></div>