Skip to content

Commit fbe3c06

Browse files
committed
Finished basic
1 parent 4b5d6f1 commit fbe3c06

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

Roadmap/22 - FUNCIONES DE ORDEN SUPERIOR/python/rigo93acosta.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,54 @@
2020
*/
2121
'''
2222

23+
"""
24+
Ejercicio
25+
"""
26+
27+
# Funcion con argumento
28+
def apply_func(func, x):
29+
return func(x)
30+
31+
print(apply_func(len, "Hola mundo"))
32+
33+
# Retorno de funcion
34+
35+
def apply_multiplier(n):
36+
def multiplier(x):
37+
return x * n
38+
return multiplier
39+
40+
x = apply_multiplier(2)
41+
print(x(5))
42+
43+
# Sistema
44+
numbers = [3, 4, 1, 5, 2]
45+
46+
# map()
47+
def applay_double(n):
48+
return n*2
49+
50+
print(list(map(applay_double, numbers)))
51+
52+
# filter()
53+
def is_even(n):
54+
return n % 2 == 0
55+
56+
print(list(filter(is_even, numbers)))
57+
58+
# sorted()
59+
print(sorted(numbers))
60+
print(sorted(numbers, reverse=True))
61+
print(sorted(numbers, key=lambda x: -x))
62+
63+
# reduce
64+
from functools import reduce
65+
def sum(x, y):
66+
return x + y
67+
68+
print(reduce(sum, numbers))
69+
70+
"""
71+
Extra
72+
"""
73+

0 commit comments

Comments
 (0)