Consider the following code, which simply calls a method on each member of a list:
class Demo:
def make_change(self):
pass
foo = [Demo(), Demo(), Demo()]
map(lambda x: x.make_change(), foo)
Is there a way to accomplish this without the long-winded lambda syntax? For example, in Scala, something similar to map(_.make_change(), foo) works. Does Python have an equivalent?
It’s not very pythonic to use map just for side-effects
so why not
This will run faster than using map
you can put it on one line if you insist, but I wouldn’t