Python-programming-exercises icon indicating copy to clipboard operation
Python-programming-exercises copied to clipboard

Map()

Open Bravebirdinc opened this issue 3 years ago • 1 comments

What exactly it means and what it does? Please explain in technical terms and in a simple language. Thank You

Bravebirdinc avatar Aug 21 '22 07:08 Bravebirdinc

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]

`

Aneousion avatar Jan 01 '23 20:01 Aneousion