Slide 20
Slide 20 text
Introducci´
on
Python funcional
fn.py
Para terminar
Funciones de orden superior
Funciones de orden superior
>>> list(map(lambda x: x**2, [1, 2, 3]))
[1, 4, 9]
>>> list(filter(lambda x: x > 1, [1, 2, 3]))
[2, 3]
>>> sorted([2, 1, 3], key=lambda x: x)
[1, 2, 3]
>>> sorted([1, 2, 3], key=lambda x: -x)
[3, 2, 1]
>>> from functools import reduce
>>> reduce(lambda x, y: x + y, [1, 2, 3])
6
>>> from functools import lru_cache
>>> cached_sum = lru_cache()(lambda x: sum(range(x)))
>>> cached_sum(4)
6
Jes´
us Espino Garc´
ıa Python funcional