You could make your own "each" function:


def each(fn, items):
    for item in items:
        fn(item)


# called thus
each(lambda x: installWow(x, 'installed by me'), wowList)

Basically it's just map, but without the results being returned. By using a function you'll ensure that the "item" variable doesn't leak into the current scope.

Answer from John Montgomery on Stack Overflow
🌐
Real Python
realpython.com › python-map-function
Python's map(): Processing Iterables Without a Loop – Real Python
March 18, 2026 - The quickest and most common approach ... to use a Python for loop. However, you can also tackle this problem without an explicit loop by using map(). In the following three sections, you’ll learn how map() works and how you can use it to process and transform iterables without a loop. map() loops over the items of an input iterable (or iterables) and returns an iterator ...
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-map-lambda.html
Python Map Lambda
The code of the lambda is typically a single expression without variables or if-statements, and does not use "return". Lambda is perfect where you have a short computation to write inline. Many programs have some sub-part which can be solved very compactly this way.
Top answer
1 of 3
12

What you are seeing here is the effect of lazy-evaluation. Python 3 made most functions like this (map, filter, zip etc) work lazily where they used to work eagerly in Python 2, that is, instead of immediately returning and materializing a data-structure when you call map(f, some_iterable), instead, map returns a map-object, which can then be iterated over to either materialize a data structure or work with the elements one-by-one (letting you work in a memory-efficient way).

>>> result = []
>>> m = map(lambda x: result.append(x), range(10))
>>> m
<map object at 0x10a0b7278>
>>> result
[]
>>> next(m)
>>> result
[0]
>>> next(m)
>>> result
[0, 1]
>>> list(m)
[None, None, None, None, None, None, None, None]
>>> result
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

However!

You should not be using map or filter or list-comprehensions for their side-effects. These are all functional constructs, and you should avoid mutating state when using them. It is simply bad style, and also, as you noticed when I called list on my map object, it creates and immediately discards a useless list of None (because functions that don't return anything implicitely return None).

So, to answer your question, yes you can use "map() for functions that does not return a value" but you shouldn't. Just use a for-loop.

2 of 3
5

map creates an iterator. It doesn't do the mapping immediately, it does it one by one as you consume the iterator. list(map(...)) immediately consumes the entire iterator to turn it into a list. But in your tests where it doesn't work, you're never consuming the iterator, so f never gets called even once.

In other words: doesn't work:

map(f, a)
print(result)

Works:

list(map(f, a))  # ← list consumes the iterator
print(result)
🌐
Medium
medium.com › @engr.tanveersultan53 › python-map-function-3c3878b8f3bd
Python map() Function. Processing Iterables Without a using a… | by Engr Muhammad Tanveer sultan | Medium
August 25, 2021 - the map function get element one by one from the list of dict and set on which the map function apply and send the element to the specified function which is given or pass the first args/parameter of the map.
🌐
Python
docs.python.org › 3 › builtins › functions.html
Built-in Functions — Python 3.14.8 documentation
The return value is None. In all cases, if the optional parts are omitted, the code is executed in the current scope. If only globals is provided, it must be a dictionary (and not a subclass of dictionary), which will be used for both the global ...
Find elsewhere
🌐
The New Stack
thenewstack.io › home › python’s map() function: iterate without looping
Python's Map() Function: Iterate without Looping - The New Stack
November 7, 2024 - Python map() is an important function when working with Python iterables (tuples, lists, etc.). Essentially, what this function does is allow you to process and transform items that can be iterated upon, meaning it can be repeated without having to use a loop. Think of the map() function this way: it’s used to apply a function to each item within an iterable and returns the results as a list.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-map-function
Python map() function | DigitalOcean
Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
🌐
datagy
datagy.io › home › python functions › python map function: transforming iterables without loops
Python map Function: Transforming Iterables without Loops • datagy
December 20, 2022 - The Python map() function allows you to transform all items in an iterable object, such as a Python list, without explicitly needing to loop over each item.
🌐
Towards Data Science
towardsdatascience.com › home › latest › does python still need the map() function?
Does Python still need the map() function? | Towards Data Science
March 5, 2025 - Compare the two versions below: one with map() combined with lambda, and another with the corresponding generator expression. This time, we will not use our double() function, but we will define it directly inside the calls: ... The two lines lead to the same results, the only difference being the type of the returned objects: the returns a map object while the latter a generator object.
🌐
LearnDataSci
learndatasci.com › solutions › python-map
Python map(function, iterable, ...) – LearnDataSci
Also, since map() is part of Python's standard library, we can use it without an import statement. For the rest of the article, we'll go deeper into how map() works and provide many unique examples to demonstrate its functionality. map() applies a function to each element of a collection (_or_ multiple collections), but an iterator is returned ...
Top answer
1 of 4
42

I think the reason why map still exists at all when generator expressions also exist, is that it can take multiple iterator arguments that are all looped over and passed into the function:

>>> list(map(min, [1,2,3,4], [0,10,0,10]))
[0,2,0,4]

That's slightly easier than using zip:

>>> list(min(x, y) for x, y in zip([1,2,3,4], [0,10,0,10]))

Otherwise, it simply doesn't add anything over generator expressions.

2 of 4
27

Because it returns an iterator, it omit storing the full size list in the memory. So that you can easily iterate over it in the future not making any pain to memory. Possibly you even don't need a full list, but the part of it, until your condition is reached.

You can find this docs useful, iterators are awesome.

An object representing a stream of data. Repeated calls to the iterator’s __next__() method (or passing it to the built-in function next()) return successive items in the stream. When no more data are available a StopIteration exception is raised instead. At this point, the iterator object is exhausted and any further calls to its __next__() method just raise StopIteration again. Iterators are required to have an __iter__() method that returns the iterator object itself so every iterator is also iterable and may be used in most places where other iterables are accepted. One notable exception is code which attempts multiple iteration passes. A container object (such as a list) produces a fresh new iterator each time you pass it to the iter() function or use it in a for loop. Attempting this with an iterator will just return the same exhausted iterator object used in the previous iteration pass, making it appear like an empty container.

🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-use-the-python-map-function
Ultimate Guide to Python Map Function for Data Processing | DigitalOcean
Master Python’s map() function with easy examples! Learn its syntax, lambda functions, user-defined functions, and using multiple iterables to optimize funct…
🌐
Py4u
py4u.net › discuss › 238483
Page not found
Python Data Types · Comparison Operators · Lists In Python · Variable Assignments · Strings In Python · This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License. Popular Tutorials · Python Data Types · Comparison Operators ·