Using map() to Apply Functions to Iterables in Python


Apply a function to each item in an iterable, returning a map object.

Source Code

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