Is there a map without result in python?
iteration, python
Solution
You can use the built-in `any` function to apply a function without return statement to any item returned by a generator without creating a list. This can be achieved like this:
any(installWow(x, 'installed by me') for x in wowList)
I found this the most concise idom for what you want to achieve.
Internally, the `installWow` function does return `None` which evaluates to `False` in logical operations. `any` basically applies an `or` reduction operation to all items returned by the generator, which are all `None` of course, so it has to iterate over all items returned by the generator. In the end it does return `False`, but that doesn't need to bother you. The good thing is: no list is created as a side-effect.
Note that this only works as long as your function returns something that evaluates to `False`, e.g., `None` or 0. If it does return something that evaluates to `True` at some point, e.g., `1`, it will not be applied to any of the remaining elements in your iterator. To be safe, use this idiom mainly for functions without return statement.
Problem
Sometimes, I just want to execute a function for a list of entries -- eg.: ``` for x in wowList: installWow(x, 'installed by me') ``` Sometimes I need this stuff for module initialization, so I don't want to have a footprint like x in global namespace. One solution would be to just use map together with lambda: ``` map(lambda x: installWow(x, 'installed by me'), wowList) ``` But this of course creates a nice list [None, None, ...] so my question is, if there is a similar function without a return-list -- since I just don't need it. (off course I can also use _x and thus not leaving visible footprint -- but the map-solution looks so neat ...)