1# Python program to demonstrate working
2# of map.
3
4# Return double of n
5def addition(n):
6 return n + n
7
8# We double all numbers using map()
9numbers = (1, 2, 3, 4)
10result = map(addition, numbers)
11print(list(result))
1#generate a list from map iterable with lambda expression
2list( map(lambda x: x*2, numeros) )
1def calculateSquare(n):
2 return n*n
3
4
5numbers = (1, 2, 3, 4)
6result = map(calculateSquare, numbers)
7print(result)
8
9# converting map object to set
10numbersSquare = list(result)
11print(numbersSquare)
1lista = [1, 2, -3, 4, 5, -9]
2def quadrado(n):
3 return n*n
4
5map(quadrado, lista)
6[1, 4, 9, 16, 25, 81]