Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

I bet the human brain is a kludge. -- Marvin Minsky


devel / comp.lang.python / Python Golf

SubjectAuthor
* Python GolfStefan Ram
`* Re: Python GolfJon Ribbens
 `* RE: Python Golf<avi.e.gross
  `- Re: Python GolfJon Ribbens

1
Python Golf

<shorter-20231107093650@ram.dialup.fu-berlin.de>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ram@zedat.fu-berlin.de (Stefan Ram)
Newsgroups: comp.lang.python
Subject: Python Golf
Date: 7 Nov 2023 08:37:29 GMT
Organization: Stefan Ram
Lines: 16
Expires: 1 Dec 2024 11:59:58 GMT
Message-ID: <shorter-20231107093650@ram.dialup.fu-berlin.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de WUTWXtkCnu36BiJFVu2CRA+NpRHc90XkvZFS5lrhqdyoTc
Cancel-Lock: sha1:QZHYk3xh/E4MrWnOEy/PD7iev8U= sha256:SrEe3ico9Pu2UktVIfX/XMqDUGo8TgortJAkP02+kUE=
X-Copyright: (C) Copyright 2023 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-1901, en-US, it, fr-FR
 by: Stefan Ram - Tue, 7 Nov 2023 08:37 UTC

I read this in a shell newsgroup:

perl -anE '$s += $F[1]; END {say $s}' in

, so I wrote

py -c "import sys; print(sum(int(F.split()[1])for F in sys.stdin))" <in

to show that this is possible with Python too.

But now people complain that it's longer than the Perl version.

Do you see ways to make it shorter (beyond removing one space
after the semicolon ";")?

Re: Python Golf

<slrnukko3f.2cil.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jon+usenet@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Python Golf
Date: Tue, 7 Nov 2023 16:06:07 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <slrnukko3f.2cil.jon+usenet@raven.unequivocal.eu>
References: <shorter-20231107093650@ram.dialup.fu-berlin.de>
Injection-Date: Tue, 7 Nov 2023 16:06:07 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d5251a882166ccc29647c6087bf32b72";
logging-data="1142794"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19JCYDHWuJuml7pUF6oIOjTXdYYXaRat9U="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:JEBKF8CV3WieNPdK5Irlzm1Q9gU=
 by: Jon Ribbens - Tue, 7 Nov 2023 16:06 UTC

On 2023-11-07, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
> I read this in a shell newsgroup:
>
> perl -anE '$s += $F[1]; END {say $s}' in
>
> , so I wrote
>
> py -c "import sys; print(sum(int(F.split()[1])for F in sys.stdin))" <in
>
> to show that this is possible with Python too.
>
> But now people complain that it's longer than the Perl version.
>
> Do you see ways to make it shorter (beyond removing one space
> after the semicolon ";")?

It's a bit of an unfair competition given that, unlike Perl,
Python is not designed to be an 'awk' replacement.

Having said that, you could make it a bit shorter:

py -c "print(sum(int(F.split()[1])for F in open(0)))" <in

RE: Python Golf

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: <avi.e.gross@gmail.com>
Newsgroups: comp.lang.python
Subject: RE: Python Golf
Date: Tue, 7 Nov 2023 12:08:35 -0500
Lines: 66
Message-ID: <mailman.191.1699376919.3828.python-list@python.org>
References: <shorter-20231107093650@ram.dialup.fu-berlin.de>
<slrnukko3f.2cil.jon+usenet@raven.unequivocal.eu>
<007701da119d$0b51d160$21f57420$@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de vdzSn69cyX39vQ4uIR7uxgWhuCawzQvuhgZtkrbukrcg==
Cancel-Lock: sha1:lqXhk0+alIEEc6FW+dcokSi069s= sha256:cqHKaDQh6BzO1o3bnqx8b0+KQKtqVuK5YPTM1F46kLE=
Return-Path: <avi.e.gross@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=IQManJyR;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.034
X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; '2023': 0.07; 'ram': 0.07;
'python.': 0.08; 'fewer': 0.09; 'grep': 0.09; 'received:108':
0.09; 'unlike': 0.09; 'subject:Python': 0.12; 'import': 0.15;
'url:mailman': 0.15; '"import': 0.16; 'alias': 0.16; 'perl,':
0.16; 'shorter': 0.16; 'utilities': 0.16; 'whatever.': 0.16;
'wrote:': 0.16; 'python': 0.16; 'message-id:@gmail.com': 0.18;
'to:addr:python-list': 0.20; 'issue': 0.21; 'written': 0.22;
'languages': 0.22; 'version': 0.23; 'command': 0.23; 'skip:p 30':
0.23; 'skip:- 10': 0.25; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'url-
ip:188.166/16': 0.25; 'space': 0.26; 'do,': 0.26; 'stefan': 0.26;
'bit': 0.27; 'version.': 0.28; 'suggest': 0.28; 'default': 0.31;
'url-ip:188/8': 0.31; 'program': 0.31; 'discussions': 0.32;
'python-list': 0.32; 'but': 0.32; 'mean': 0.34; 'header:In-Reply-
To:1': 0.34; 'received:google.com': 0.34; 'handling': 0.35;
'from:addr:gmail.com': 0.35; 'people': 0.36; 'using': 0.37;
"it's": 0.37; 'hard': 0.37; 'way': 0.38; 'could': 0.38; 'read':
0.38; 'on.': 0.39; 'wrote': 0.39; 'something': 0.40; 'family':
0.60; 'provide': 0.60; 'remember': 0.61; 'from:': 0.62; 'to:':
0.62; 'seen': 0.62; 'love': 0.62; 'feel': 0.63; 'becomes': 0.64;
're:': 0.64; 'lead': 0.67; 'mind.': 0.67; 'that,': 0.67; 'below':
0.69; 'too.': 0.70; 'longer': 0.71; 'sent:': 0.78; 'major': 0.78;
'brevity': 0.84; 'capture': 0.84; 'characters': 0.84; 'golf':
0.84; 'jon': 0.84; 'competition': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1699376917; x=1699981717; darn=python.org;
h=thread-index:content-language:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:from:to:cc:subject:date:message-id:reply-to;
bh=/x8QdaomNv+aXKkTEumkuKqLkVvDUd0tShzJazPIpQ0=;
b=IQManJyRfDG7h9o2GF2glkct0lSxpbO1cSLdg7gWCEsEtU2Gd5t2pMvdiL7Sr3I2mn
Z4BuSlb/WW0hil4IudWt0hixod8jBFY+Rl2PEc7K9fBKXi7uyWHLU0U59c8BEJyJHpCa
rcM5c8EkZ3VQ3fwN2/lhpIhpAZb8lVesMTf8lnMS1A4H7++krLlab5hTjF81ORn47sZr
gEM8Ve71nKddaUFP9gzZSSeNtIlU+A5/6Aiybjjow+8TVbA8c5nCjONDVKrlEIaiUXZQ
k6nwB4hr3YPhlk2zLeTtst7D7LX737d+Zckt3/b9q26+FvYHB4FsvRZxeGIKK/wfd6dz
9lPA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1699376917; x=1699981717;
h=thread-index:content-language:content-transfer-encoding
:mime-version:message-id:date:subject:in-reply-to:references:to:from
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=/x8QdaomNv+aXKkTEumkuKqLkVvDUd0tShzJazPIpQ0=;
b=saLECRbOX2uxV2/KeRZtBfNOrggxNo9LSq9IlZtas8wy8XmRuDA6pTwXFXIvAoPOoQ
QACfskE+jHYkfRMCQNbB7y38GLZ3a059dpWbWJvGfGkxcdP/YkaKWib+ggdsBdQ60vrI
qxOyj1WT8PvleDLyrJCQPyrsGtZjaje/YJUZMN7ZKRmv9SqMiXCa+y4Tnnr01DTP0eIW
Tg2zz/LYOd4tV36HsbuFEA6+mWep4irtVPRC2waUGj57qus82debwb0cKCb5L0yUW9QO
ZsOvDD1Qwl6/WyY8CtJmrqpAS/yGyiQtHmCr6bhHSXW/Po5/bUsRypapDgA+FpVu70XV
obTA==
X-Gm-Message-State: AOJu0YxwXOYFJ6gC208HcCG9J3Uz7JbonEbwk82qMj6iFeHrhFQOCLSo
lk7wGIeG5yzDTC2FURilN5PJg+bVOmg=
X-Google-Smtp-Source: AGHT+IGUjzEO/DxdUSLHKxnPsvBy1RMTHBlm8KHpbhkYGFRj3Fy5J8G+56gp0MWepEMjwldYstC7jw==
X-Received: by 2002:a05:620a:2a01:b0:778:8b8a:37e with SMTP id
o1-20020a05620a2a0100b007788b8a037emr38662036qkp.21.1699376916887;
Tue, 07 Nov 2023 09:08:36 -0800 (PST)
In-Reply-To: <slrnukko3f.2cil.jon+usenet@raven.unequivocal.eu>
X-Mailer: Microsoft Outlook 16.0
Content-Language: en-us
Thread-Index: AQFxavm7KSiMXPA0YaJrx7sqwLXjuwIbtkiNsS+DrfA=
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
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: <007701da119d$0b51d160$21f57420$@gmail.com>
X-Mailman-Original-References: <shorter-20231107093650@ram.dialup.fu-berlin.de>
<slrnukko3f.2cil.jon+usenet@raven.unequivocal.eu>
 by: <avi.e.gross@gmail.com> - Tue, 7 Nov 2023 17:08 UTC

Discussions like this feel a bit silly after a while. How long something is
to type on a command line is not a major issue and brevity can lead to being
hard to remember too especially using obscure references.

Consider that the Perl version as shown below does not need to import
anything. If you had python import sys by default and perhaps even create a
briefer alias for sys.stdin, then this gets shorter:

py -c "import sys; print(sum(int(F.split()[1])for F in sys.stdin))" <in

becomes

py -c "print(sum(int(F.split()[1])for F in sys.stdin))" <in

or even

py -c "print(sum(int(F.split()[1])for F in stdin))" <in

As noted, some languages are designed with different perspectives in mind. I
have seen books and other internet resources that suggest ways to take many
of the UNIX utilities I used to love to place in pipelines and replace each
with a one-liner written in Python or Perl or AWK or whatever. An example
might be a program that does a head(or a tail) or a grep or a sed and so on.
One liners can often capture a good portion of what such programs do, albeit
handling the multiple options many provide may not be worth doing versus
making a small family of one-liners that together provide most of the
functionality.

But just because it can be done; it does not mean it is a good way or that
programs that do it with fewer characters are in most ways better.

Let's not flog Python.

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com@python.org> On
Behalf Of Jon Ribbens via Python-list
Sent: Tuesday, November 7, 2023 11:06 AM
To: python-list@python.org
Subject: Re: Python Golf

On 2023-11-07, Stefan Ram <ram@zedat.fu-berlin.de> wrote:
> I read this in a shell newsgroup:
>
> perl -anE '$s += $F[1]; END {say $s}' in
>
> , so I wrote
>
> py -c "import sys; print(sum(int(F.split()[1])for F in sys.stdin))" <in
>
> to show that this is possible with Python too.
>
> But now people complain that it's longer than the Perl version.
>
> Do you see ways to make it shorter (beyond removing one space
> after the semicolon ";")?

It's a bit of an unfair competition given that, unlike Perl,
Python is not designed to be an 'awk' replacement.

Having said that, you could make it a bit shorter:

py -c "print(sum(int(F.split()[1])for F in open(0)))" <in
--
https://mail.python.org/mailman/listinfo/python-list

Re: Python Golf

<slrnukl2om.2cil.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: jon+usenet@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Python Golf
Date: Tue, 7 Nov 2023 19:08:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <slrnukl2om.2cil.jon+usenet@raven.unequivocal.eu>
References: <shorter-20231107093650@ram.dialup.fu-berlin.de>
<slrnukko3f.2cil.jon+usenet@raven.unequivocal.eu>
<007701da119d$0b51d160$21f57420$@gmail.com>
<mailman.191.1699376919.3828.python-list@python.org>
Injection-Date: Tue, 7 Nov 2023 19:08:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d5251a882166ccc29647c6087bf32b72";
logging-data="1216132"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OIuS1BrMriq5CjLnlah1WQI+j6w70t+g="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:fK8ucDQZ0l8b6d5wotkQ0QCP+q0=
 by: Jon Ribbens - Tue, 7 Nov 2023 19:08 UTC

On 2023-11-07, <avi.e.gross@gmail.com> <avi.e.gross@gmail.com> wrote:
> Discussions like this feel a bit silly after a while. How long
> something is to type on a command line is not a major issue and
> brevity can lead to being hard to remember too especially using
> obscure references.

Of course it's silly, that's why it's called "golf"!

It would be basically insane to use open(0) instead of sys.stdin
like this except where the length of the source code overrides
all other considerations - which is essentially never, unless
playing code golf...


devel / comp.lang.python / Python Golf

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor