Re: Why can’t for-of be applied to iterators?

Jason Orendorff jason.orendorff at gmail.com
Tue Jun 11 07:39:13 PDT 2013


On Tue, Jun 11, 2013 at 8:42 AM, Jason Orendorff
<jason.orendorff at gmail.com>wrote:

> Please look at any Python codebase. The right-hand side of a for loop is
> most often just an identifier or simple expression naming a collection. You
> will see a few calls to enumerate(), .items(), and so on, but they do not
> predominate. Sometimes it's a list literal.
>
>
> I will quantify this later today.
>

In case I don't get to this, here is the code you can use:
  https://gist.github.com/jorendorff/5757221

It's easy to run on any Python codebase. In the Python 3.3.1 distribution,
for example, only about 12% of for loops require an explicit indication of
what kind of iterator is wanted. That is, the default is used about 88% of
the time.

    49.0% - N - just an identifier
    15.0% - R - call to range()
    15.5% - A - an attribute-expression, like self.parts
    6.4% - I - call to .items() or .iteritems()
    4.2% - L - literal string, tuple, list, or set
    2.7% - E - call to enumerate()
    1.3% - K - call to .keys() or .iterkeys()
    1.0% - V - call to .values() or .itervalues()

    4.9% - O - everything else
           (examples: module.split('.')[1:], dirs[:], args[1:],
fixers[node.type])

-j
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130611/cb9a7da7/attachment.html>


More information about the es-discuss mailing list