424,066 Members | 2,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,066 IT Pros & Developers. It's quick & easy.

What does the map() function do?

P: 5
What does the map() function do? Can you explain me with an example?
1 Week Ago #1
Share this Question
Share on Google+
3 Replies

P: 1
Itís a simple function that returns the upper case string representation of the input object.

def print_iterator(it):
for x in it:
print(x, end=' ')
print('') # for new line
# map() with string
map_iterator = map(to_upper_case, 'abc')
1 Week Ago #2

P: 4
map() executes the function we pass to it as the first argument; it does so on all elements of the iterable in the second argument. Letís take an example, shall we?

>>> for i in map(lambda i:i**3, (2,3,7)):

This gives us the cubes of the values 2, 3, and 7.
1 Week Ago #3

P: 1
The Map object holds key-value pairs and remembers the original insertion order of the keys. Any value (both objects and primitive values) may be used as either a key or a value.
more: https://developer.mozilla.org/en-US/...al_Objects/Map
1 Week Ago #4

Post your reply

Sign in to post your reply or Sign up for a free account.