How is lambda() used with map() in python?

0 votes
How is lambda() used with map() in python? Also, it would be nice if you gave me an example. Thanks you
May 20 in Python by Neel
7 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

The map() function in Python takes in a function and a list as an argument. The function is called with a lambda function and a list and a new list is returned which contains all the lambda modified items returned by that function for each item. 

Example:

# Python code to illustrate 
# map() with lambda() 
# to get double of a list. 
li = [5, 7, 22, 97, 54, 62, 77, 23, 73, 61] 
final_list = list(map(lambda x: x*2 , li)) 
print(final_list) 

Output:

[10, 14, 44, 194, 108, 124, 154, 46, 146, 122]
answered May 20 by Takeshi

Related Questions In Python

0 votes
1 answer

How random.seed(): is used in python?

Pseudo-random number generators work by performing some ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 56,140 points
26 views
0 votes
1 answer

What is absolute import in Python and how is it used?

An absolute {import, path, URL} tells you exactly how ...READ MORE

answered Nov 30, 2018 in Python by Nymeria
• 3,500 points

edited Dec 10, 2018 by Nymeria 61 views
+4 votes
7 answers
+1 vote
1 answer

How to check if a string is null in python

Try this: if cookie and not cookie.isspace(): # the ...READ MORE

answered Aug 20, 2018 in Python by Priyaj
• 56,140 points
1,212 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
69 views
+4 votes
6 answers
0 votes
1 answer

How Lambda() is used with filter() in python?

The filter() function in Python takes in ...READ MORE

answered May 20 in Python by Rakshi
12 views
0 votes
1 answer

How do I use lambda() with reduce() in python?

The reduce() function in Python takes in ...READ MORE

answered May 20 in Python by Umer
19 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.