A loop is good enough for this task, but if for some reason you must use lambda and map, you can do it like this:

list(map(lambda x: print(f"I only have {x} friends, but they are awesome."), range(2, 5)))

The expression needs to be wrapped in list() as the map function is eagerly executed, which means it doesn't calculate the output until it is needed.

Answer from Sagar Patil on Stack Overflow
🌐
Caisbalderas
caisbalderas.com › blog › iterating-with-python-lambdas
Iterating With Python Lambdas - Carlos Isaac Balderas
[v * 5 for v in x] --> map(lambda for v: v * 5, in x) --> map(lambda v : v * 5, x) A slightly more difficult example. The for loop representation is straightforward; iterate over x, multiply the odd values by 5 and add them to the list y.
🌐
Stanford CS
cs.stanford.edu › people › nick › py › python-map-lambda.html
Python Map Lambda
To work with map(), the lambda should have one parameter in, representing one element from the source list. Choose a suitable name for the parameter, like n for a list of numbers, s for a list of strings. The result of map() is an "iterable" map object which mostly works like a list, but it ...
Discussions

How to write a Python for loop as a lambda function with apply or map instead? - Stack Overflow
How would I write this code using a lambda function and apply or map? I have looked at several blog posts, etc., but for some reason I feel like I am missing something. I think it should be really ... More on stackoverflow.com
🌐 stackoverflow.com
Python: Using Map/Lambda instead of for loop - Stack Overflow
How can i use the below code with map and lambda function ? for i in range(1,11): print "*" * i How to achieve the same with map and lambda function map(lambda x:print "*"*x ,range(1,11)) More on stackoverflow.com
🌐 stackoverflow.com
June 5, 2017
Does the built-in map() in python actually doesn't use loops? How does the map iterate?
Have a look: https://github.com/python/cpython/blob/main/Python/bltinmodule.c#L1215 More on reddit.com
🌐 r/learnpython
10
11
June 26, 2021
python - Lambda Range For Loop - Stack Overflow
Note: I am not sure if I should ask this question here or at CodeGolf, so I am going to post it here in case it is appropriate. I am trying to make a for loop in python using lambdas that follows ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Real Python
realpython.com › python-map-function
Python's map(): Processing Iterables Without a Loop – Real Python
March 18, 2026 - This first argument to map() is a transformation function. In other words, it’s the function that transforms each original item into a new (transformed) item. Even though the Python documentation calls this argument function, it can be any Python callable. This includes built-in functions, classes, methods, lambda functions, and user-defined functions.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-map-with-lambda
Python map with Lambda - GeeksforGeeks
July 23, 2025 - In Python, the map() function is used to apply a function to every item in an iterable like a list or tuple. Using a lambda function inside the map can make this even more powerful lambda().
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-iterating-with-python-lambda
Python: Iterating With Python Lambda - GeeksforGeeks
July 23, 2025 - Then, we do to the square of it ... to iterate over list l1 # filter is used to find odd numbers l2 = list(map(lambda v: v ** 2, filter(lambda u: u % 2, l1))) # print list print(l2)...
Find elsewhere
🌐
Note.nkmk.me
note.nkmk.me › home › python
Apply a Function to Items of a List in Python: map() | note.nkmk.me
May 15, 2023 - l_3 = [100, 200, 300, 400] print(list(map(lambda x, y, z: x * y * z, l_1, l_2, l_3))) # [1000, 8000, 27000] ... The same process as map() can be achieved with list comprehensions and generator expressions. l = [-2, -1, 0] print([abs(x) for x in l]) # [2, 1, 0] print([x**2 for x in l]) # [4, 1, 0] l_1 = [1, 2, 3] l_2 = [10, 20, 30] print([x * y for x, y in zip(l_1, l_2)]) # [10, 40, 90]
🌐
Python Tips
book.pythontips.com › en › latest › map_filter.html
4. Map, Filter and Reduce — Python Tips 0.1 documentation
def multiply(x): return (x*x) def add(x): return (x+x) funcs = [multiply, add] for i in range(5): value = list(map(lambda x: x(i), funcs)) print(value) # Output: # [0, 0] # [1, 2] # [4, 4] # [9, 6] # [16, 8] As the name suggests, filter creates a list of elements for which a function returns true. Here is a short and concise example: number_list = range(-5, 5) less_than_zero = list(filter(lambda x: x < 0, number_list)) print(less_than_zero) # Output: [-5, -4, -3, -2, -1] The filter resembles a for loop but it is a builtin function and faster.
🌐
GeeksforGeeks
geeksforgeeks.org › python-lambda-anonymous-functions-filter-map-reduce
Python Lambda Functions - GeeksforGeeks
... The lambda function doubles each number. map() iterates through a and applies the transformation. The reduce() function in Python takes in a function and a list as an argument.
Published: December 11, 2024
🌐
Python Course
python-course.eu › advanced-python › lambda-filter-reduce-map.php
4. Lambda Operator, filter, reduce and map | Advanced
Enough that Guido van Rossum wrote hardly a year later: "After so many attempts to come up with an alternative for lambda, perhaps we should admit defeat. I've not had the time to follow the most recent rounds, but I propose that we keep lambda, so as to stop wasting everybody's talent and time on an impossible quest." We can see the result: lambda, map() and filter() are still part of core Python.
🌐
Finxter
blog.finxter.com › home › learn python blog › python for loop inside lambda
Python For Loop Inside Lambda - Be on the Right Side of Change
June 13, 2021 - There are two ways of doing this: x = [2, 3, 4, 5, 6] y = [v * 5 for v in x if v % 2] print(y) # [15, 25] x = [2, 3, 4, 5, 6] y = list(map(lambda v: v * 5, filter(lambda u: u % 2, x))) print(y) # [15, 25]
🌐
Reddit
reddit.com › r/learnpython › does the built-in map() in python actually doesn't use loops? how does the map iterate?
r/learnpython on Reddit: Does the built-in map() in python actually doesn't use loops? How does the map iterate?
June 26, 2021 -

I was going through this map() function in python and interestingly in all tutorials, it is mentioned. We can use map() instead of loops to make a transformation on an iterable. Does the map function inside uses for loop or while loop? how does it iterate then? also, what is the Big O notion for map?

🌐
Analytics Vidhya
analyticsvidhya.com › home › an explanation to python’s lambda, map, filter and reduce
An Explanation to Python's Lambda, Map, Filter and Reduce
October 21, 2024 - The approach shown above can be improved using list comprehension but that too will use for loop. So, there’s a faster way to do the same without using explicit for loop. Python’s map function does that.
🌐
Enki
enki.com › post › apply-a-function-to-each-element-in-a-list---python-s-map-function
Enki | Blog - Apply a Function to Each Element in a List - Python’s map function
Lambdas are great for short operations that you won’t reuse. map() can handle multiple iterables at once, applying your function in parallel across them: Here, the lambda function takes two inputs: one from each list, adding them together. It showcases map()'s versatility with parallel operations.
🌐
Medium
medium.com › data-science › understanding-the-use-of-lambda-expressions-map-and-filter-in-python-5e03e4b18d09
Python’s Lambda Expressions, Map and Filter | by Luciano Strika | TDS Archive | Medium
July 21, 2022 - On the other hand, map returns a normal list in Python 2.7. So that’s where lambdas and maps make a sort of synergy: As fluid as writing a line using map can be, it can become even more fluid if you can invent your small function on the fly. Once you get the hang of it, you’ll start thinking in terms of mapping, and appreciate this feature. But beware, unreadable code can fester very quickly if maps are left unguarded. For completion, I will also introduce you to filter.
🌐
LearnDataSci
learndatasci.com › solutions › python-map
Python map(function, iterable, ...) – LearnDataSci
Here, map() takes in three lists of different sizes and a lambda expression that concatenates three values using an f-string.