Python Funcional


In [1]:
soma = lambda x, y: x + y

In [2]:
soma(2, 3)


Out[2]:
5

In [3]:
numeros = [1,2,3,4,5]

In [5]:
map(lambda x: x* 2, numeros)


Out[5]:
<map at 0x7fbdcc20ddd8>

In [6]:
for valor in map(lambda x: x* 2, numeros):
    print(valor)


2
4
6
8
10

In [7]:
for valor in filter(lambda x: x % 2 == 0, numeros):
    print(valor)


2
4

In [8]:
[x * 2 for x in numeros if x % 2 == 0]


Out[8]:
[4, 8]

In [9]:
[x * 2 for x in numeros]


Out[9]:
[2, 4, 6, 8, 10]

In [ ]: