+ 2

What use of map() function in python?

13th Aug 2019, 12:50 PM
Aashiq Ahmed
Aashiq Ahmed - avatar
2 Respuestas
+ 6
#You can use map to call a function for each item in a list. And it will return an iterable object of the returned values. new_list = list(map(func, [4, 7, 5, 0, 3])) #corresponds: new_list = [func(4), func(7), func(5), func(0), func(3)] #Using map function is faster in runspeed than using for loop for the same purpose: new_list = [] for item in [4, 7, 5 0, 3]: new_list.append(item) #But using list comprehension is also fast: new_list = [func(item) for item in [4, 7, 5, 0, 3]]
13th Aug 2019, 1:06 PM
Seb TheS
Seb TheS - avatar