when to use map function in python
#The map function is used to do a certain function to a certain iterable #It takes a function and an iterable numbers = [1,2,3,4,5,6,7,8,9,10] x = map(lambda nom : nom*nom, numbers) print(list(x)) #So here my function is the lambda and the iterable is the numbers list #And with this I apply nom*nom to every item to the list # if I didn't put the list function before x it would print map object at .....
Python map()
# Program to double each item in a list using map() my_list = [1, 5, 4, 6, 8, 11, 3, 12] new_list = list(map(lambda x: x * 2 , my_list)) print(new_list)
map in python
items = [1, 2, 3, 4, 5] squared = [] for i in items: squared.append(i**2)
Source: book.pythontips.com