Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

map in Python

📅 2012-Apr-25 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

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