WHAT IS MAP IN PYTHON
The map() function in python applies the given function to the iterable and returns a list of the results. We can pass multiple iterables to the map function.
Syntax: map(function, iterable, ...)
The returned value from map() function called a map object can be passed to functions like list, set etc
Example:
def test(n): return len(n) li = ['one', 'two', 'three', 'four'] print(map(test,li))
Output:
<map object at 0x000001CA4D787E50>
The map object is located at the memory location given here.
def test(n): return len(n) li = ['one', 'two', 'three', 'four'] # we have converted the map object into a list print(list(map(test, li)))
Output:
[3, 3, 5, 4]
Subscribe
Login
Please login to comment
0 Discussion