Map function with example in python

0 votes
Can you explain Map function with example in python? Thank you
May 23, 2019 in Python by Trisha
108 views

1 answer to this question.

0 votes

The map function executes the function_object for each element in the sequence and returns a list of the elements modified by the function object.

syntax:

map(function_object, iterable1, iterable2,...)

Example:

def multiply2(x):
  return x * 2
    map(multiply2, [1, 2, 3, 4])  # Output [2, 4, 6, 8]

map executes multiply2 function for each element in the list i.e. 1, 2, 3, 4 and returns [2, 4, 6, 8]

answered May 23, 2019 by Imran

Related Questions In Python

0 votes
1 answer

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

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

answered May 20, 2019 in Python by Takeshi
105 views
0 votes
1 answer

I want to download a file from the website by web scraping. Can anyone explain how to do this in jupyter lab (python) with an example?

Hey, Web scraping is a technique to automatically ...READ MORE

answered Apr 7, 2020 in Python by Gitika
• 65,870 points
645 views
0 votes
1 answer

What is the difference between map() and filter() function in python?

The map() function is a type of ...READ MORE

answered Jun 25, 2020 in Python by Sirajul
• 59,050 points
494 views
0 votes
1 answer

What is the use of raw_input function in Python?

raw_input fuction is no longer available in ...READ MORE

answered May 2, 2018 in Python by aayushi
• 750 points
328 views
0 votes
2 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,989 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,523 views
0 votes
1 answer

How can I build a recursive function in python?

I'm wondering whether you meant "recursive". Here ...READ MORE

answered Sep 19, 2018 in Python by Priyaj
• 58,100 points
211 views
0 votes
1 answer

'foreach' function in Python 3?

Yes, there is a "foreach" in python. ...READ MORE

answered Oct 24, 2018 in Python by Priyaj
• 58,100 points
6,092 views