[Python-ideas] Calling a function of a list without accumulating results
terry at jon.es
Wed Sep 26 23:42:50 CEST 2007
What's the most compact way to repeatedly call a function on a list without
accumulating the results?
While I can accumulate results via
a = [f(x) for x in mylist]
or with a generator, there doesn't seem to be a way to do this without
accumulating the results. I guess I need to either use the above and ignore
the result, or use
for x in mylist:
I run into this need quite frequently. If I write
[f(x) for x in mylist]
with no assignment, will Python notice that I don't want the accumulated
results and silently toss them for me?
A possible syntax change would be to allow the unadorned
f(x) for x in mylist
And raise an error if someone tries to assign to this.
More information about the Python-ideas