Obviously, using values
, items
, and keys
is bad practice in Python 2.X in virtually every instance, because you'll allocate an extra list you don't actually need. Thus, for some time, the recommended best practice was to use iteritems
/itervalues
, and to use the built-in __iter__
if you wanted to enumerate the dict
's keys.
With the backport of Python 3's keys
, values
, and items
to Python 2.7 as viewkeys
, viewvalues
, and viewitems
, I'm wondering what the actual performance tradeoffs are of the view*
family of functions, vs. their iter*
counterparts. Is the only reason to continue using the iter*
functions that you are targeting Python 2.6 and earlier, or can the older iter*
methods be faster than the newer view*
methods in certain contexts?