Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Always draw your curves, then plot your reading.


devel / comp.lang.python / on the popularity of loops while and for

SubjectAuthor
* on the popularity of loops while and forHope Rouselle
+* Re: on the popularity of loops while and forStefan Ram
|`* Re: on the popularity of loops while and forHope Rouselle
| `* Re: on the popularity of loops while and forStestagg
|  `* Re: on the popularity of loops while and forStefan Ram
|   `- Re: on the popularity of loops while and forStestagg
+* Re: on the popularity of loops while and forChris Angelico
|`- Re: on the popularity of loops while and forHope Rouselle
`* Re: on the popularity of loops while and forTerry Reedy
 `- Re: on the popularity of loops while and forHope Rouselle

1
on the popularity of loops while and for

<86eeadlmpg.fsf@jevedi.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14769&group=comp.lang.python#14769

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!dsd0/0sLSmZ4OKvnSrnhDQ.user.46.165.242.75.POSTED!not-for-mail
From: hrouse...@jevedi.com (Hope Rouselle)
Newsgroups: comp.lang.python
Subject: on the popularity of loops while and for
Date: Sat, 28 Aug 2021 10:31:55 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86eeadlmpg.fsf@jevedi.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="38072"; posting-host="dsd0/0sLSmZ4OKvnSrnhDQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:FAj4ffyN6KAI6FmLtbAEV61JdgA=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Hope Rouselle - Sat, 28 Aug 2021 13:31 UTC

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!

Re: on the popularity of loops while and for

<statistics-20210828161946@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14771&group=comp.lang.python#14771

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: on the popularity of loops while and for
Date: 28 Aug 2021 15:20:54 GMT
Organization: Stefan Ram
Lines: 33
Expires: 1 Dec 2021 11:59:58 GMT
Message-ID: <statistics-20210828161946@ram.dialup.fu-berlin.de>
References: <86eeadlmpg.fsf@jevedi.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de Uu7E8Y4K/0uS6+FpUw3bJwn/j6i3DXzkZXE2wkEnm55POJ
X-Copyright: (C) Copyright 2021 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sat, 28 Aug 2021 15:20 UTC

Hope Rouselle <hrouselle@jevedi.com> writes:
>Have you guys ever measured something like that in a casual or serious

import ast
import pathlib
rootname=r'''<ABSOLUTE PATH TO A DIRECTORY WITH SOURCE CODE>'''
rootpath=pathlib.Path(rootname)
rootiterable=rootpath.glob('**/*.py')
first = True
WhileCount = 0
ForCount = 0
for filepath in rootiterable:
try:
with filepath.open(encoding="utf-8") as file:
source=file.read()
parse=ast.parse(source, filename=str(file))
for entry in ast.walk(parse):
if isinstance(entry, ast.While):
WhileCount+=1
print( f"{ForCount=}, {WhileCount=}" )
elif isinstance(entry, ast.For):
ForCount+=1
print( f"{ForCount=}, {WhileCount=}" )
except SyntaxError as inst:
if first:
print( f"{sys.exc_info()[ 0 ] =}" )
print( f"{type( inst ) =}" )
print( f"{inst.args =}" )
print( f"{inst =}" )
print( f"skipping {filepath}." )
first=False

Re: on the popularity of loops while and for

<86sfyts23t.fsf@jevedi.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14775&group=comp.lang.python#14775

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!dsd0/0sLSmZ4OKvnSrnhDQ.user.46.165.242.75.POSTED!not-for-mail
From: hrouse...@jevedi.com (Hope Rouselle)
Newsgroups: comp.lang.python
Subject: Re: on the popularity of loops while and for
Date: Sat, 28 Aug 2021 18:15:02 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86sfyts23t.fsf@jevedi.com>
References: <86eeadlmpg.fsf@jevedi.com>
<statistics-20210828161946@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="30369"; posting-host="dsd0/0sLSmZ4OKvnSrnhDQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:dznG9FSl17nzwwsvHTFkMBwsics=
 by: Hope Rouselle - Sat, 28 Aug 2021 21:15 UTC

ram@zedat.fu-berlin.de (Stefan Ram) writes:

> Hope Rouselle <hrouselle@jevedi.com> writes:
>>Have you guys ever measured something like that in a casual or serious
>
> import ast
> import pathlib
> rootname=r'''<ABSOLUTE PATH TO A DIRECTORY WITH SOURCE CODE>'''
> rootpath=pathlib.Path(rootname)
> rootiterable=rootpath.glob('**/*.py')
> first = True
> WhileCount = 0
> ForCount = 0
> for filepath in rootiterable:
> try:
> with filepath.open(encoding="utf-8") as file:
> source=file.read()
> parse=ast.parse(source, filename=str(file))
> for entry in ast.walk(parse):
> if isinstance(entry, ast.While):
> WhileCount+=1
> print( f"{ForCount=}, {WhileCount=}" )
> elif isinstance(entry, ast.For):
> ForCount+=1
> print( f"{ForCount=}, {WhileCount=}" )
> except SyntaxError as inst:
> if first:
> print( f"{sys.exc_info()[ 0 ] =}" )
> print( f"{type( inst ) =}" )
> print( f"{inst.args =}" )
> print( f"{inst =}" )
> print( f"skipping {filepath}." )
> first=False

You are so wonderful! Thanks quite a lot. Here's what I got:

ForCount=18703, WhileCount=2505

I have pretty much just the standard libraries and a couple more ---
sympy and some xlsxwriter library.

Re: on the popularity of loops while and for

<mailman.482.1630187028.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14779&group=comp.lang.python#14779

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: on the popularity of loops while and for
Date: Sun, 29 Aug 2021 07:43:35 +1000
Lines: 23
Message-ID: <mailman.482.1630187028.4164.python-list@python.org>
References: <86eeadlmpg.fsf@jevedi.com>
<CAPTjJmqP6oOfP4J8T8ib9DN9nenwhCk+8JfNTVJoRk00FPsbgg@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de wYLyuWAcIOZBMInmWFyLAwxm42Qy25F1vQszEsmdG/9A==
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=eBmd3LdL;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.004
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'comments': 0.04;
"python's": 0.05; 'loop': 0.07; 'loops.': 0.07; 'sun,': 0.07;
'aug': 0.09; 'parse': 0.09; 'practice.': 0.09; 'way?': 0.09;
'chrisa': 0.16; 'easy,': 0.16; 'from:addr:rosuav': 0.16;
'from:name:chris angelico': 0.16; 'loops': 0.16; 'lot,': 0.16;
'subject:popularity': 0.16; 'subject:while': 0.16; 'using.': 0.16;
'wrote:': 0.16; 'syntax': 0.16; 'python': 0.16; 'libraries': 0.20;
"i'd": 0.23; 'to:addr:python-list': 0.23; 'wrong': 0.27; "i'll":
0.28; 'coming': 0.29; 'but': 0.31; 'do.': 0.32; 'to:name:python':
0.32; 'message-id:@mail.gmail.com': 0.33; 'using': 0.33;
'received:209.85.166': 0.33; 'header:In-Reply-To:1': 0.33;
'subject:for': 0.33; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'trying': 0.36; 'recommend': 0.37;
'received:209.85': 0.38; 'those': 0.38; "it's": 0.38; 'something':
0.38; 'received:209': 0.38; 'word': 0.38; 'use': 0.38; 'source':
0.38; 'url-ip:151.101.36.223/32': 0.38; 'url-ip:151.101.36/24':
0.38; 'among': 0.61; 'english': 0.61; 'love': 0.61; 'hope': 0.61;
'ever': 0.63; 'look': 0.66; 'analysis': 0.70; 'know.': 0.72;
'life': 0.76; '2021': 0.84; 'casual': 0.84; 'strings': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=wmQvQ56b1jaDBOXRDvbR+agyltBhkaltS4mpHMIqS6s=;
b=eBmd3LdLeQV1PWq5PKJSRAQLYLxxxYqFxbGXiCtT/67y8WOTDDTyFDsfUco83dtVDJ
PD+JXvyGrEPgZVurZrE/9fFIlvMn16EgZbtaKSQHj9bPASStmSTLE2/VHHYQuESAXjKn
K4cYq0rXD69916DOrA4EnRUlHroF7bYLH3mKu4A0wkfh0cnHbhDMnL3ysECjmdjF7CB2
OOycfG9L0QO3L7sNZSY3+s0WeE9HY3NHFUm4OssjBgoW3ueN5AAr2Y+92D8SdtBwXW2p
q4IJJ0a2TaSVnkzDzInVVMsbwcPHrSqVt4qXmtNSVPT1SzPP7vE4bzq0xf/szRwe4ToD
7ZTQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=wmQvQ56b1jaDBOXRDvbR+agyltBhkaltS4mpHMIqS6s=;
b=Tj8d3PSE/aGHavVEUX04VDb53iWkPvHux8eJQ5RJHRidKxkmOcOqJju1hyLBVMuLSz
muwxMa9K6tHSynhGKN1qol5QYx5b3i2win2Ou8A5qVd0NTThNHWNjAN4+nGSBEm2V9te
KL2Ijo7j9oPq2hHPlIK5dRL4mro4uW81WdQ/E8TFzxgUg2gFXFjRl0wmnDRLHhL183Ka
IuLf8jq99JpcukZytymBEyh/D17/tszNwC0QzTHMWkryMGi9Kpt1jZY9vxtBMIE86K9F
ucw+PVt9DeqMJ4T0nNxRFflb2RCYWOrruNChnSjVlW1J4oW4+ICPMDM/YM48yXrYu1oY
N1cw==
X-Gm-Message-State: AOAM532p1vPwuL5hdpm+aLDN6xQeXeP8nru8b9N5XGM7Ir5y7mPCiFym
QRLA7yxOV2G8YNSn4dGnb4w/FakaqHcMfOQ/LLTfuKKUiF3HIg==
X-Google-Smtp-Source: ABdhPJyLZYqUhxF3LiYNHj1kKOwKPWBN8sOkVhwgbPpXqFZHFUHP40rjyI3pF/jjIe32n00RJwMwTiIhLgD/UfFR8uU=
X-Received: by 2002:a6b:f817:: with SMTP id o23mr12479511ioh.205.1630187026616;
Sat, 28 Aug 2021 14:43:46 -0700 (PDT)
In-Reply-To: <86eeadlmpg.fsf@jevedi.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmqP6oOfP4J8T8ib9DN9nenwhCk+8JfNTVJoRk00FPsbgg@mail.gmail.com>
X-Mailman-Original-References: <86eeadlmpg.fsf@jevedi.com>
 by: Chris Angelico - Sat, 28 Aug 2021 21:43 UTC

On Sun, Aug 29, 2021 at 7:40 AM Hope Rouselle <hrouselle@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.

ChrisA

Re: on the popularity of loops while and for

<mailman.484.1630188325.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14781&group=comp.lang.python#14781

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: stest...@gmail.com (Stestagg)
Newsgroups: comp.lang.python
Subject: Re: on the popularity of loops while and for
Date: Sat, 28 Aug 2021 23:05:12 +0100
Lines: 53
Message-ID: <mailman.484.1630188325.4164.python-list@python.org>
References: <86eeadlmpg.fsf@jevedi.com>
<statistics-20210828161946@ram.dialup.fu-berlin.de>
<86sfyts23t.fsf@jevedi.com>
<CACFDE8Y92TmwiujNcqdicoJ8+=e6AOyc=RwoH59jwGWehdq6pw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de ggWRfiXEU1+xkoJ8pVHQhQJFjZOqJaWWGDCAEsm4YBnQ==
Return-Path: <stestagg@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=OYPqQQo5;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'library.': 0.05;
'url:mailman': 0.09; 'ast': 0.09; 'aug': 0.09; 'elif': 0.09;
'received:209.85.219': 0.09; 'skip:\xc2 20': 0.09; 'writes:':
0.09; '\xc2\xa0with': 0.09; 'import': 0.14; '&gt;': 0.14;
'first:': 0.16; 'loops': 0.16; 'print(': 0.16;
'subject:popularity': 0.16; 'subject:while': 0.16; '\xc2\xa0for':
0.16; 'wrote:': 0.16; 'url:listinfo': 0.16; 'libraries': 0.20;
'url-ip:188.166.95.178/32': 0.20; 'url-ip:188.166.95/24': 0.20;
'url-ip:188.166/16': 0.23; 'sat,': 0.23; "i'd": 0.23; 'to:addr
:python-list': 0.23; 'cc:2**0': 0.27; 'url-ip:188/8': 0.29; 'but':
0.31; 'message-id:@mail.gmail.com': 0.33; 'header:In-Reply-To:1':
0.33; 'subject:for': 0.33; 'received:google.com': 0.34;
'from:addr:gmail.com': 0.35; 'path': 0.37; 'couple': 0.37;
'received:209.85': 0.38; 'those': 0.38; 'something': 0.38;
'received:209': 0.38; 'source': 0.38; 'directory': 0.40; 'pretty':
0.40; 'completely': 0.60; 'skip:w 10': 0.61; 'hope': 0.61; 'skip:r
30': 0.61; 'skip:\xc2 10': 0.62; 'true': 0.63; 'ever': 0.63;
'skip:r 20': 0.64; 'interested': 0.66; 'skip:f 30': 0.71; 'skip:f
20': 0.76; '2021': 0.84; 'casual': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=VO5Z6LxCzJO50AfILY0HnJpaKGLH0iAtFvGTtPngx9A=;
b=OYPqQQo5zlQNgBPdSppoOq664Kz53fe+nxij7Mucl4u7EkJlgfsEbcIhNx5XpYrhhR
vbFdihEyGfKyT4h3PcrfOlOpvqaYFuOaIqYvVqxjk7/koTfvMt/eZPDkJ5mSXykYgqlB
KrkoYu/6cjOhvRwKTlk1+iXg2+QMRIUhMdkK1t6TqOsIvsw3pZnYZqthbQ47hsv8c1x+
XhDWsgTKa/SUGkwFtWm9iZSB2QYEuXVT7o9mytAdPA9X+0aAo1OBhyJdXAJhbFhYqgks
lU/HHX7sQZy/oCRae3ajLC8vON1rfY3yNW1ChQ2HjcbOr91V1Ci6C8FGowDdjiMQRj+P
56RQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=VO5Z6LxCzJO50AfILY0HnJpaKGLH0iAtFvGTtPngx9A=;
b=YuwZJ1Sd3VEd2cxrfBm1mRHcCncKjF/dSHTML0lcw4gLN+t1M6m33OWz9Wm0cTAwMn
zhZWHlPCHb/hOz0MSFbltv2+gMTDNDjtCNXPUhXv4/nD+BOM5A2ubk22xFNsE0E87Acx
RFhd2bAaGTak40Wlgt7s8RZuMKI9bHF7C8OAlAMVQzLyHr805bbyEYlZSyqrCKkE5RxE
wQe6tT+b4X5+P0HVBVwPCfN6fWFmshrCRk2Z1hU8sa4hBHdKxQ+5j7XY0hEdwgtXTfWD
vDlv39ljCoiSfhw6Uwit+r1AC0/E80+S/3TjEofssyKxfswWw2+jFF9IXJArXfZyS7pg
u8Ug==
X-Gm-Message-State: AOAM530BnLBImTFDhXDy0Rf+5GqmRUZbJm5nddA36nwJ52Kq1aLx6wK6
O5Y34lqS/LJJVboTvtBT3OBsz7arxFw5rAoXb6FX+o0Z
X-Google-Smtp-Source: ABdhPJzqRuwMwOzndxv260W9dpvNTafoWzs8/wdaVzsQ89yFZxEe4pT7+xdpYaQWrC5F3LScYABJHzWBEz1OOJINU2I=
X-Received: by 2002:a25:938a:: with SMTP id a10mr12809941ybm.481.1630188323158;
Sat, 28 Aug 2021 15:05:23 -0700 (PDT)
In-Reply-To: <86sfyts23t.fsf@jevedi.com>
X-Content-Filtered-By: Mailman/MimeDel 2.1.34
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CACFDE8Y92TmwiujNcqdicoJ8+=e6AOyc=RwoH59jwGWehdq6pw@mail.gmail.com>
X-Mailman-Original-References: <86eeadlmpg.fsf@jevedi.com>
<statistics-20210828161946@ram.dialup.fu-berlin.de>
<86sfyts23t.fsf@jevedi.com>
 by: Stestagg - Sat, 28 Aug 2021 22:05 UTC

If you're doing this analysis, I'd be pretty interested in how many of
those while loops where 'while True:'

I'd wager 75%. But may be completely off

Steve

On Sat, 28 Aug 2021 at 23:03, Hope Rouselle <hrouselle@jevedi.com> wrote:

> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>
> > Hope Rouselle <hrouselle@jevedi.com> writes:
> >>Have you guys ever measured something like that in a casual or serious
> >
> > import ast
> > import pathlib
> > rootname=r'''<ABSOLUTE PATH TO A DIRECTORY WITH SOURCE CODE>'''
> > rootpath=pathlib.Path(rootname)
> > rootiterable=rootpath.glob('**/*.py')
> > first = True
> > WhileCount = 0
> > ForCount = 0
> > for filepath in rootiterable:
> > try:
> > with filepath.open(encoding="utf-8") as file:
> > source=file.read()
> > parse=ast.parse(source, filename=str(file))
> > for entry in ast.walk(parse):
> > if isinstance(entry, ast.While):
> > WhileCount+=1
> > print( f"{ForCount=}, {WhileCount=}" )
> > elif isinstance(entry, ast.For):
> > ForCount+=1
> > print( f"{ForCount=}, {WhileCount=}" )
> > except SyntaxError as inst:
> > if first:
> > print( f"{sys.exc_info()[ 0 ] =}" )
> > print( f"{type( inst ) =}" )
> > print( f"{inst.args =}" )
> > print( f"{inst =}" )
> > print( f"skipping {filepath}." )
> > first=False
>
> You are so wonderful! Thanks quite a lot. Here's what I got:
>
> ForCount=18703, WhileCount=2505
>
> I have pretty much just the standard libraries and a couple more ---
> sympy and some xlsxwriter library.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Re: on the popularity of loops while and for

<while-True-20210828233854@ram.dialup.fu-berlin.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14782&group=comp.lang.python#14782

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram...@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Re: on the popularity of loops while and for
Date: 28 Aug 2021 22:42:25 GMT
Organization: Stefan Ram
Lines: 49
Expires: 1 Dec 2021 11:59:58 GMT
Message-ID: <while-True-20210828233854@ram.dialup.fu-berlin.de>
References: <86eeadlmpg.fsf@jevedi.com> <statistics-20210828161946@ram.dialup.fu-berlin.de> <86sfyts23t.fsf@jevedi.com> <CACFDE8Y92TmwiujNcqdicoJ8+=e6AOyc=RwoH59jwGWehdq6pw@mail.gmail.com> <mailman.484.1630188325.4164.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de IaSb+l1SYjSsEfCOE1rk2AjRlsO4WAWBT+sbRFrycr8vy3
X-Copyright: (C) Copyright 2021 Stefan Ram. All rights reserved.
Distribution through any means other than regular usenet
channels is forbidden. It is forbidden to publish this
article in the Web, to change URIs of this article into links,
and to transfer the body without this notice, but quotations
of parts in other Usenet posts are allowed.
X-No-Archive: Yes
Archive: no
X-No-Archive-Readme: "X-No-Archive" is set, because this prevents some
services to mirror the article in the web. But the article may
be kept on a Usenet archive server with only NNTP access.
X-No-Html: yes
Content-Language: en-US
Accept-Language: de-DE, en-US, it, fr-FR
 by: Stefan Ram - Sat, 28 Aug 2021 22:42 UTC

Stestagg <stestagg@gmail.com> writes:
>If you're doing this analysis, I'd be pretty interested in how many of
>those while loops where 'while True:'

Here, about 40 %.

Below is a new version that is supposed to also count "if True:"
and "if 1:" and also removes a bug with the exception handling
(missing "import sys" and missing "UnicodeDecodeError"). I'm not
experienced in using the AST module, so there might still be bugs
in the program!

import ast
import pathlib
import sys
rootname=r'''PATH TO SOURCE DIR (WITHOUT A BACKQUOTE AT THE END)'''
rootpath=pathlib.Path(rootname)
rootiterable=rootpath.glob('**/*.py')
WhileCount = 0
TrueCount = 0
ForCount = 0
for filepath in rootiterable:
try:
with filepath.open(encoding="utf-8") as file:
source=file.read()
parse=ast.parse(source, filename=str(file))
for entry in ast.walk(parse):
if isinstance(entry, ast.While):
WhileCount+=1
if ( isinstance( entry.test, ast.Constant ) and
hasattr( entry.test, "value") and
( isinstance( entry.test.value, bool )
and entry.test.value == True or
isinstance( entry.test.value, int )
and entry.test.value != 0 )):
TrueCount+=1
print( f"{ForCount=}, {WhileCount=}, {TrueCount=}" )
elif isinstance(entry, ast.For):
ForCount+=1
print( f"{ForCount=}, {WhileCount=}" )
except ( SyntaxError, UnicodeDecodeError )as inst:
print( f"skipping {filepath}." )
print( f"{sys.exc_info()[ 0 ] =}" )
print( f"{type( inst ) =}" )
print( f"{inst.args =}" )
print( f"{inst =}\n" )
print( f"{ForCount=}, {WhileCount=}, {TrueCount=}" )

Re: on the popularity of loops while and for

<mailman.486.1630191731.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14784&group=comp.lang.python#14784

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: tjre...@udel.edu (Terry Reedy)
Newsgroups: comp.lang.python
Subject: Re: on the popularity of loops while and for
Date: Sat, 28 Aug 2021 17:54:07 -0400
Lines: 25
Message-ID: <mailman.486.1630191731.4164.python-list@python.org>
References: <86eeadlmpg.fsf@jevedi.com>
<sgeba1$b1s$1@ciao.gmane.io>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de qoYDsGT5JtXN8bdCg7sL0gyhngTcIrrJ67LUtS4Mp3uw==
Return-Path: <python-python-list@m.gmane-mx.org>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'comments': 0.04;
"python's": 0.05; 'loop': 0.07; 'loops.': 0.07; 'excludes': 0.09;
'message-id:@ciao.gmane.io': 0.09; 'practice.': 0.09;
'received:ciao.gmane.io': 0.09; 'received:gmane.io': 0.09;
'received:list': 0.09; 'terry': 0.09; 'easy,': 0.16;
'from:addr:udel.edu': 0.16; 'loops': 0.16; 'lot,': 0.16;
'received:116.202': 0.16; 'received:116.202.254': 0.16;
'received:116.202.254.214': 0.16; 'subject:popularity': 0.16;
'subject:while': 0.16; 'wrote:': 0.16; 'python': 0.16;
'libraries': 0.20; "i'd": 0.23; 'to:addr:python-list': 0.23;
"i'll": 0.28; 'header:User-Agent:1': 0.31; 'but': 0.31; 'am,':
0.31; 'do.': 0.32; 'guess': 0.32; 'header:In-Reply-To:1': 0.33;
'subject:for': 0.33; 'trying': 0.36; 'file': 0.38; 'those': 0.38;
'something': 0.38; 'use': 0.38; 'least': 0.40; 'common': 0.60;
'among': 0.61; 'english': 0.61; 'hope': 0.61; 'replaced': 0.65;
'look': 0.66; 'files:': 0.69; 'received:116': 0.71; 'life': 0.76;
'strings': 0.84
X-Injected-Via-Gmane: http://gmane.org/
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
In-Reply-To: <86eeadlmpg.fsf@jevedi.com>
Content-Language: en-US
X-Mailman-Approved-At: Sat, 28 Aug 2021 19:02:10 -0400
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <sgeba1$b1s$1@ciao.gmane.io>
X-Mailman-Original-References: <86eeadlmpg.fsf@jevedi.com>
 by: Terry Reedy - Sat, 28 Aug 2021 21:54 UTC

On 8/28/2021 9:31 AM, Hope Rouselle wrote:
> I'd like get a statistic of how often each loop is used in practice.

My guess is that for loops are at least twice as common as while loops.

> 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.

Try something like

fors = 0
for file in files:
for line in file:
if re.match(r"/s*for .* in ", line):
fors += 1

This excludes comprehensions, which have replaced some for loops.

--
Terry Jan Reedy

Re: on the popularity of loops while and for

<mailman.489.1630192199.4164.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14787&group=comp.lang.python#14787

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: stest...@gmail.com (Stestagg)
Newsgroups: comp.lang.python
Subject: Re: on the popularity of loops while and for
Date: Sun, 29 Aug 2021 00:09:45 +0100
Lines: 61
Message-ID: <mailman.489.1630192199.4164.python-list@python.org>
References: <86eeadlmpg.fsf@jevedi.com>
<statistics-20210828161946@ram.dialup.fu-berlin.de>
<86sfyts23t.fsf@jevedi.com>
<CACFDE8Y92TmwiujNcqdicoJ8+=e6AOyc=RwoH59jwGWehdq6pw@mail.gmail.com>
<mailman.484.1630188325.4164.python-list@python.org>
<while-True-20210828233854@ram.dialup.fu-berlin.de>
<CACFDE8ZbgLYGREajiJpMm6xP6NndqX701qJ6eqno2LR5DScafw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 8CzfHFkBvLoY/n//oVmp/gQjI+yA5m/0UDDLZX5sa4aA==
Return-Path: <stestagg@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=FU/rxk0i;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'ram': 0.07; 'sun,': 0.07;
'url:mailman': 0.09; '(without': 0.09; 'ast': 0.09; 'aug': 0.09;
'elif': 0.09; 'int': 0.09; 'received:209.85.219': 0.09; 'writes:':
0.09; 'import': 0.14; '"import': 0.16; '&quot;if': 0.16; 'bugs':
0.16; 'code.\xc2\xa0': 0.16; 'email addr:zedat.fu-berlin.de&gt;':
0.16; 'email name:&lt;ram': 0.16; 'loops': 0.16; 'module,': 0.16;
'print(': 0.16; 'program!': 0.16; 'removes': 0.16;
'subject:popularity': 0.16; 'subject:while': 0.16; 'wrote:': 0.16;
'url:listinfo': 0.16; 'code.': 0.19; 'bug': 0.20; 'url-
ip:188.166.95.178/32': 0.20; 'url-ip:188.166.95/24': 0.20;
'version': 0.22; 'url-ip:188.166/16': 0.23; 'exception': 0.23;
"i'd": 0.23; 'to:addr:python-list': 0.23; 'thanks!': 0.25;
'cc:2**0': 0.27; 'stefan': 0.27; 'url-ip:188/8': 0.29; 'there':
0.31; "i'm": 0.32; 'here,': 0.32; 'message-id:@mail.gmail.com':
0.33; 'using': 0.33; 'skip:" 20': 0.33; 'header:In-Reply-To:1':
0.33; 'subject:for': 0.33; 'received:google.com': 0.34; 'missing':
0.35; '"if': 0.35; 'handling': 0.35; 'from:addr:gmail.com': 0.35;
'count': 0.37; "that's": 0.37; 'received:209.85': 0.38;
'received:209': 0.38; 'source': 0.38; 'pretty': 0.40; 'skip:e 10':
0.60; 'skip:w 10': 0.61; 'experienced': 0.61; 'skip:r 30': 0.61;
'true': 0.63; 'look': 0.66; 'interested': 0.66; 'below': 0.71;
'interesting': 0.71; 'skip:f 30': 0.71; 'skip:f 20': 0.76;
'supposed': 0.77; '2021': 0.84; "people's": 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to
:cc; bh=C4XP6L87mbfSska8UNJkIJE1sjdktTRmOePBn90k7LI=;
b=FU/rxk0iBowyGC3DNNPft9QhHSqygLI7SfS1yG8GZlR3HcSmNACZa+uCDBfiUuuLn5
hzWNfho6lLCJE3KKzITYd/v6366P27/kMRb26gI0GA0UbpD9qAnQKdcnQEYwcWu7Uj3s
hzr7B4+i3/xxXF+hBHjnNa2jO41qKXATEcYw5HZLoWE+VLgrBJTDloEnsQK5EdCFomNh
LFGLy3sfQVruSTOab0Wvt8kw5nroyAfwElJv1CPruh1qii8Tqsu+Y5I215ybQyMgZb0b
TEpxYmNNgMmqyOJeF8kZGQJpNSbu8EDhsUQHmW70vcZ05ERbQtZYQ/AjHvooPLy6PJR7
ccuQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to:cc;
bh=C4XP6L87mbfSska8UNJkIJE1sjdktTRmOePBn90k7LI=;
b=LRvhhVYS5GFj3I7zbsZw6rz8pxs5UqhecwvNl9f0ydxos96dPyMW4wjBOOJz6lJI9n
lFhucjY5FG51MPT7Q5734tvj/5OYvWu1wQVBmTD2ebdrnXSq8sCk/yVx9obttMDpzBk+
3xbCvuucmZXqMw/2aoOcFJ4uaWx0c9Ngxkk0dpWBYxBZxqNayqgb1rnbgeNfzlivv20Z
XIFjztIFYRc0k4+Lza023EEXftooKZuyy+bJ+sB/5zIU7tAD5LrRh4+I+OznK6UO6/j7
3fwhiA23zFikDCH4mQ42JayWr4Fg4EbSawISHY9dcxva/AOzwvdkoDtFYXFUIfVCa9kc
4v+w==
X-Gm-Message-State: AOAM531QhMWXX6V62yFGohQvW36ZXdyAmvMZdvz3XaINOnGqWYToS/mV
NNAl87qyW+hq0f091w/6NuLrARrDV8aG7hGTtoO+hZ0VlGc=
X-Google-Smtp-Source: ABdhPJzHGf3C1iDXDc5sCKZOtg7l3yYMBwFtN/OgLQDrsFyXyxWkAUiCC7Xuxmf7l0Q3w1n1fCyk64tu9jyYbma9MdY=
X-Received: by 2002:a25:11c5:: with SMTP id 188mr13265799ybr.135.1630192195612;
Sat, 28 Aug 2021 16:09:55 -0700 (PDT)
In-Reply-To: <while-True-20210828233854@ram.dialup.fu-berlin.de>
X-Content-Filtered-By: Mailman/MimeDel 2.1.34
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CACFDE8ZbgLYGREajiJpMm6xP6NndqX701qJ6eqno2LR5DScafw@mail.gmail.com>
X-Mailman-Original-References: <86eeadlmpg.fsf@jevedi.com>
<statistics-20210828161946@ram.dialup.fu-berlin.de>
<86sfyts23t.fsf@jevedi.com>
<CACFDE8Y92TmwiujNcqdicoJ8+=e6AOyc=RwoH59jwGWehdq6pw@mail.gmail.com>
<mailman.484.1630188325.4164.python-list@python.org>
<while-True-20210828233854@ram.dialup.fu-berlin.de>
 by: Stestagg - Sat, 28 Aug 2021 23:09 UTC

On Sun, 29 Aug 2021 at 00:04, Stefan Ram <ram@zedat.fu-berlin.de> wrote:

> Stestagg <stestagg@gmail.com> writes:
> >If you're doing this analysis, I'd be pretty interested in how many of
> >those while loops where 'while True:'
>
> Here, about 40 %.

Thanks! That's an interesting stat. I might have to look more into how
while loops are actually used in other people's code.

>
> Below is a new version that is supposed to also count "if True:"
> and "if 1:" and also removes a bug with the exception handling
> (missing "import sys" and missing "UnicodeDecodeError"). I'm not
> experienced in using the AST module, so there might still be bugs
> in the program!
>
> import ast
> import pathlib
> import sys
> rootname=r'''PATH TO SOURCE DIR (WITHOUT A BACKQUOTE AT THE END)'''
> rootpath=pathlib.Path(rootname)
> rootiterable=rootpath.glob('**/*.py')
> WhileCount = 0
> TrueCount = 0
> ForCount = 0
> for filepath in rootiterable:
> try:
> with filepath.open(encoding="utf-8") as file:
> source=file.read()
> parse=ast.parse(source, filename=str(file))
> for entry in ast.walk(parse):
> if isinstance(entry, ast.While):
> WhileCount+=1
> if ( isinstance( entry.test, ast.Constant ) and
> hasattr( entry.test, "value") and
> ( isinstance( entry.test.value, bool )
> and entry.test.value == True or
> isinstance( entry.test.value, int )
> and entry.test.value != 0 )):
> TrueCount+=1
> print( f"{ForCount=}, {WhileCount=}, {TrueCount=}" )
> elif isinstance(entry, ast.For):
> ForCount+=1
> print( f"{ForCount=}, {WhileCount=}" )
> except ( SyntaxError, UnicodeDecodeError )as inst:
> print( f"skipping {filepath}." )
> print( f"{sys.exc_info()[ 0 ] =}" )
> print( f"{type( inst ) =}" )
> print( f"{inst.args =}" )
> print( f"{inst =}\n" )
> print( f"{ForCount=}, {WhileCount=}, {TrueCount=}" )
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>

Re: on the popularity of loops while and for

<86y28fm7y4.fsf@jevedi.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14885&group=comp.lang.python#14885

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!4+bwgJ580lENslyh7E5FoA.user.46.165.242.75.POSTED!not-for-mail
From: hrouse...@jevedi.com (Hope Rouselle)
Newsgroups: comp.lang.python
Subject: Re: on the popularity of loops while and for
Date: Thu, 02 Sep 2021 10:18:59 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86y28fm7y4.fsf@jevedi.com>
References: <86eeadlmpg.fsf@jevedi.com>
<CAPTjJmqP6oOfP4J8T8ib9DN9nenwhCk+8JfNTVJoRk00FPsbgg@mail.gmail.com>
<mailman.482.1630187028.4164.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="7409"; posting-host="4+bwgJ580lENslyh7E5FoA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:QsHTuoTkr/zdMuTKtX/RXUCpdW4=
 by: Hope Rouselle - Thu, 2 Sep 2021 13:18 UTC

Chris Angelico <rosuav@gmail.com> writes:

> On Sun, Aug 29, 2021 at 7:40 AM Hope Rouselle <hrouselle@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.

Re: on the popularity of loops while and for

<86sfynm7qm.fsf@jevedi.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=14886&group=comp.lang.python#14886

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!aioe.org!4+bwgJ580lENslyh7E5FoA.user.46.165.242.75.POSTED!not-for-mail
From: hrouse...@jevedi.com (Hope Rouselle)
Newsgroups: comp.lang.python
Subject: Re: on the popularity of loops while and for
Date: Thu, 02 Sep 2021 10:23:29 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86sfynm7qm.fsf@jevedi.com>
References: <86eeadlmpg.fsf@jevedi.com> <sgeba1$b1s$1@ciao.gmane.io>
<mailman.486.1630191731.4164.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="14327"; posting-host="4+bwgJ580lENslyh7E5FoA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:w5XvsG1B3JiG7uScyelF2NxnOZ8=
 by: Hope Rouselle - Thu, 2 Sep 2021 13:23 UTC

Terry Reedy <tjreedy@udel.edu> writes:

> On 8/28/2021 9:31 AM, Hope Rouselle wrote:
>> I'd like get a statistic of how often each loop is used in practice.
>
> My guess is that for loops are at least twice as common as while loops.

Scanning just the Python 3.9.6's Lib/ directory --- using the ast module
and the program someone kindly posted here ---, I found for loop
appearing 598% more times than while loops. The ratio was something
like that 6.98..., excluding files that due to encoding errors (or
whatever) could not be parsed. (I reported these numbers elsewhere in
this thread.)

>> 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.
>
> Try something like
>
> fors = 0
> for file in files:
> for line in file:
> if re.match(r"/s*for .* in ", line):
> fors += 1
>
> This excludes comprehensions, which have replaced some for loops.

That's nice too. Thanks for the alternative.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor