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, 2019 in Python by Neel
51 views

1 answer to this question.

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, 2019 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
• 57,640 points
89 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,520 points

edited Dec 10, 2018 by Nymeria 201 views
0 votes
1 answer

How to create a unicode string in python with the string eg: This is a string?

Hey, @Roshni, It is very simple to execute, ...READ MORE

answered Jun 23 in Python by Gitika
• 36,530 points
57 views
+4 votes
7 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,342 views
0 votes
0 answers
+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, 2019 in Python by Rakshi
65 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, 2019 in Python by Umer
250 views