Python-programming-exercises
Python-programming-exercises copied to clipboard
Map()
What exactly it means and what it does? Please explain in technical terms and in a simple language. Thank You
It is used for applying a function to an iterable object like a list, string or tuple. It takes the function and 1 or more iterable as arguments. e.g. ` def add_one(x): return x+1
i = [1,2,3]
print(list(map(add_one,i)))
THIS PRINTS [2, 3, 4]
Two iterables
def add_both(x, y):
return x + y
first = [2, 3, 4] second = [1, 2, 3]
print(list(map(add_both, first, second)))
THIS PRINTS [3, 5, 7]
`