Skip to content

Commit b2b6aef

Browse files
committed
Intermediate: Día 3
1 parent e6d20cc commit b2b6aef

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

Intermediate/03_lambdas.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Clase en vídeo (19/10/22): https://www.twitch.tv/videos/1628654998
2+
3+
### Lambdas ###
4+
5+
sum_two_values = lambda first_value, second_value: first_value + second_value
6+
print(sum_two_values(2, 4))
7+
8+
multiply_values = lambda first_value, second_value: first_value * second_value - 3
9+
print(multiply_values(2, 4))
10+
11+
def sum_three_values(value):
12+
return lambda first_value, second_value: first_value + second_value + value
13+
14+
print(sum_three_values(5)(2, 4))
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Clase en vídeo (19/10/22): https://www.twitch.tv/videos/1628654998
2+
3+
### Higher Order Functions ###
4+
5+
from functools import reduce
6+
7+
def sum_one(value):
8+
return value + 1
9+
10+
def sum_five(value):
11+
return value + 5
12+
13+
def sum_two_values_and_add_value(first_value, second_value, f_sum):
14+
return f_sum(first_value + second_value)
15+
16+
print(sum_two_values_and_add_value(5, 2, sum_one))
17+
print(sum_two_values_and_add_value(5, 2, sum_five))
18+
19+
### Closures ###
20+
21+
def sum_ten(original_value):
22+
def add(value):
23+
return value + 10 + original_value
24+
return add
25+
26+
add_closure = sum_ten(1)
27+
print(add_closure(5))
28+
print((sum_ten(5))(1))
29+
30+
### Built-in Higher Order Functions ###
31+
32+
numbers = [2, 5, 10, 21, 3, 30]
33+
34+
# Map
35+
36+
def multiply_two(number):
37+
return number * 2
38+
39+
print(list(map(multiply_two, numbers)))
40+
print(list(map(lambda number: number * 2, numbers)))
41+
42+
# Filter
43+
44+
def filter_greater_than_ten(number):
45+
if number > 10:
46+
return True
47+
return False
48+
49+
print(list(filter(filter_greater_than_ten, numbers)))
50+
print(list(filter(lambda number: number > 10, numbers)))
51+
52+
# Reduce
53+
54+
def sum_two_values(first_value, second_value):
55+
return first_value + second_value
56+
57+
print(reduce(sum_two_values, numbers))

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
##### Si consideras útil esta actividad, apóyala haciendo "★ Star" en el repositorio. ¡Gracias!
99

1010
> ---
11-
> **🔴 PRÓXIMA CLASE: Miércoles 19 de Octubre a las 20:00 (hora España)**
11+
> **🔴 PRÓXIMA CLASE: Martes 25 de Octubre a las 20:00 (hora España)**
1212
>
1313
> Mientras, aprovecha para practicar unos [retos de programación](https://retosdeprogramacion.com/semanales2022) y así ir mejorando poco a poco.
1414
>
15-
> En [Discord](https://discord.gg/YHMbyTCQ?event=1030422684342952027) tienes creado un [evento](https://discord.gg/YHMbyTCQ?event=1030422684342952027) para que consultes la hora de tu país y añadas un recordatorio.
15+
> En [Discord](https://discord.gg/NQTS5UX4?event=1034099515050958900) tienes creado un [evento](https://discord.gg/NQTS5UX4?event=1034099515050958900) para que consultes la hora de tu país y añadas un recordatorio.
1616
>
1717
> *Finalizada la clase, se actualizará el repositorio con los nuevos recursos*
1818
>
@@ -55,6 +55,7 @@ Curso en el que continuamos aprendiendo Python desde sus bases, siguiendo la rut
5555
5656
* [Clase 06/10/22 - Dates y List Comprehension](https://www.twitch.tv/videos/1611014007)
5757
* [Clase 13/10/22 - Resolución retos de programación](https://www.twitch.tv/videos/1623225956)
58+
* [Clase 19/10/22 - Lambdas y Funciones de orden superior](https://www.twitch.tv/videos/1628654998)
5859

5960
## Información importante y preguntas frecuentes
6061

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy