on the popularity of loops while and for
Hope Rouselle
hrouselle at jevedi.com
Thu Sep 2 09:18:59 EDT 2021
Chris Angelico <rosuav at gmail.com> writes:
> On Sun, Aug 29, 2021 at 7:40 AM Hope Rouselle <hrouselle at jevedi.com> wrote:
>>
>> I'd like get a statistic of how often each loop is used in practice.
>>
>> I was trying to take a look at the Python's standard libraries --- those
>> included in a standard installation of Python 3.9.6, say --- to see
>> which loops are more often used among while and for loops. Of course,
>> since English use the preposition ``for'' a lot, that makes my life
>> harder. Removing comments is easy, but removing strings is harder. So
>> I don't know yet what I'll do.
>>
>> Have you guys ever measured something like that in a casual or serious
>> way? I'd love to know. Thank you!
>
> For analysis like this, I recommend using the Abstract Syntax Tree:
>
> https://docs.python.org/3/library/ast.html
>
> You can take a Python source file, parse it to the AST, and then walk
> that tree to see what it's using. That will avoid any false positives
> from the word "for" coming up in the wrong places.
Wonderful. Someone here actually posted a nice ``routine'' that does
the job marvelously well. I had the impression the poster posted only
to solve my request --- impressive and appreciated.
More information about the Python-list
mailing list