The map() Function for Applying Functions in Python


Apply a function to every item in an iterable.

Source Code

def square(x):
    return x * x
numbers = [1, 2, 3, 4]
squared = list(map(square, numbers))
print(squared)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments