[Python-ideas] Inline assignments using "given" clauses

Jacco van Dorp j.van.dorp at deonet.nl
Fri May 11 10:04:44 EDT 2018

A while ago, we had this gem:

2018-04-06 8:19 GMT+02:00 Serhiy Storchaka <storchaka at gmail.com>:
> Using currently supported syntax:
>     smooth_signal = [average for average in [0] for x in signal for average in [(1-decay)*average + decay*x]]

Go ahead and understand that line in 1 go. It's currently legal syntax
for a running average for a smoothing signal, which remembers
something about it. (Subject: Proposal: A Reduce-Map Comprehension and
a "last" builtin)

You're not allowed to work it out bit by bit, just understand the
entire line or nothing. Any failure of yours proves my point.

> [João]
> How do you read something like " while (cmd := get_command()).token != CMD_QUIT:" in plain english?

while open-paren cee em dee colon is call get-underscore-command
close-paren dot token doesn't equal all-caps cee em dee underscore
quit colon.

Might be some dutch in there.

But far more importantly, I can hold the concept into my head, or just
the parts of it that I need. How we call it in english is actually not
a good argument - whether we can easily mentally parse it is, since I
tend not to code by voice command, but with a keyboard. Your mileage
may vary, but I think we should optimize for keyboard coding over
voice chat coding. And when I need to refer to it, I say "this bit
here" or I copy paste it.

More information about the Python-ideas mailing list