On 13.05.2018 11:23, Peter O'Connor wrote:
*Correction: Above code should read:
outputs = []
state = initial_state
for inp in inputs:
out, state = my_update_func(inp, state)
outputs.append(out)
Question still stands if this type of code needs compaction in the first
place?
List comprehensions usually have some sort of declarative touch (set
builder notation).
Even though, striving for a more compacted version, I tend to think that
using a declarative version of it doesn't serve it well in the long term.
We recently came across the following code snippet in our source base
(1st answer of
https://stackoverflow.com/questions/480214/how-do-you-remove-duplicates-from-a-list-whilst-preserving-order).
It was absolutely not comprehensible.
Your example is inherently imperative because the internal state changes
from iteration to iteration; something unusual for set builder notation.
Regards,
Sven
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/