Map in Python

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

new_sequence = map(function, old_sequence)


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.

metres = [1, 3, 5]

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

< Lambda   |   Filter >

© 2019 SyntaxDB. All Rights Reserved.