On 11/05/18 15:04, Jacco van Dorp wrote:
A while ago, we had this gem:

2018-04-06 8:19 GMT+02:00 Serhiy Storchaka<storch...@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.

Personally I thought it proved the point that you shouldn't be trying to squash things like that into a list comprehension in the first place, because

  average = 0
  smooth_signal = []
  for x in signal:
    average = (1 - decay) * average + decay * x
    smooth_signal.append(average)

is quite a bit more comprehensible.

--
Rhodri James *-* Kynesim Ltd
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to