map in Python

The built-in map function is used to apply a function on the items of an iterable and return the results in another iterable.

# Syntax: map( function, iterable )
list( map( abs, [ -1, 4, -99 ] ) )
# [1,4,99]

If the function being used in map requires more than one input, that many number of parameters can be fed to it, by passing in that many number of iterables to map.

# Syntax: map( function, iterable0, iterable1, ... )
# pow() takes two input parameters
list( map( pow, [2,3,4], [3,3,3] ) )
# [8,27,64]

For more info, see Built-in Functions.

Tried with: Python 3.2.2


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.