×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python map() with Lambda Function

Last Updated : April 25, 2025

The map() function is used to apply the function to all items of an iterable collection like list, tuple etc and it returns the list of the result after performing the functionality defined in the applied function.

The lambda function is an anonymous function - that means the function which does not have any name.

Implementing map() with lambda function

You can implement the map() function with a lambda to apply a specific operation to each element in a sequence.

Here's the syntax for using map() with a lambda function in Python:

map(lambda arguments: expression, iterable)

Example Using map() with lambda

You can implement temperature conversion efficiently using the map() function along with lambda expressions. This approach allows applying a function to each item in a list without using explicit loops:

# list of the values
temp = [12, 45, 6, 78, 5, 26, 67]
print("Orignal Data   : ", temp)

# converting values to cel using map and lambda
cel = list(map(lambda f: 5 / 9 * (f - 32), temp))
print("Celcuis Data   : ", cel)

# converting values to far using map and lambda
far = list(map(lambda c: 9 / 5 * c + 32, temp))
print("Farenhiet Data : ", far)

The output of the above code will be:

Orignal Data   :  [12, 45, 6, 78, 5, 26, 67]
Celcuis Data   :  [-11.11111111111111, 7.222222222222222, -14.444444444444445, 
25.555555555555557, -15.0, -3.3333333333333335, 19.444444444444446]
Farenhiet Data :  [53.6, 113.0, 42.8, 172.4, 41.0, 
78.80000000000001, 152.60000000000002]

Python map() with Lambda Exercise

Select the correct option to complete each statement about using map() with lambda functions in Python.

  1. The map() function takes ___ arguments: a function and an iterable.
  2. map(lambda x: x * 2, [1, 2, 3]) will return:
  3. The result of map() is a ___ in Python 3, which needs to be converted using list() to view all results.

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.