Functions

Map in Python

Map is a first class function used to run a function on an entire sequence.


Syntax
new_sequence = map(function, old_sequence)

Notes

In Python 2, the map function returns a list by default. In Python 3, the map function returns an iterator, which must be wrapped into a list if that's the desired result.

Maps are most often used with lambdas.


Example
metres = [1, 3, 5]

metres_to_cm = list(map((lambda m: m * 100), metres))
#should return [100, 300, 500]

< Lambda   |   Filter >

© 2018 SyntaxDB. All Rights Reserved.