pub-3785248829033902 | Python: map() | - Big data with Python

| Python: map() |

The map() function applies a function to every member of an iterable and returns the result. Typically, one would use an anonymous inline function as defined by lambda, but it is possible to use any function. 

The best way to learn new things is to take a practical approach of the things you want to learn. Here is a fragment of code that demonstrates the use of the map()  statement in Python:

Æ’ python command

items = [1, 2, 3, 4, 5]
squared = list(map(lambda x: x**2, items))

print(squared)

output

[1, 4, 9, 16, 25]


Previous
Next Post »