Skip to content

Commit b79dd02

Browse files
authored
Merge pull request #4024 from raulG91/raulG91
#22 - Python
2 parents 2d9ea33 + f9b0c00 commit b79dd02

File tree

1 file changed

+62
-0
lines changed
  • Roadmap/22 - FUNCIONES DE ORDEN SUPERIOR/python

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
from datetime import datetime
3+
from functools import reduce
4+
5+
#Funciones de orden superior
6+
list1 = [20,8,3,2,13,17,25]
7+
8+
#Python function that receive a function as argument
9+
new_list = filter(lambda x: x%2 == 0,list1)
10+
11+
for element in new_list:
12+
print(element)
13+
14+
#FUnction that returns a function
15+
def multiply_operation(value1,value2):
16+
return value1 * value2
17+
18+
def operation(value1,value2,function):
19+
return multiply_operation(value1,value2)
20+
21+
print("Result: ",operation(2,3,multiply_operation))
22+
23+
#Extra
24+
25+
student_list = [
26+
{
27+
"name": "Raul",
28+
"birth_date": "11/09/1991",
29+
"qualifications": [10,9,10,9]
30+
},
31+
{
32+
"name":"Maria",
33+
"birth_date": "19/04/1992",
34+
"qualifications": [9,7,8,5.5]
35+
},
36+
{
37+
"name":"Juan",
38+
"birth_date": "20/10/2000",
39+
"qualifications": [5,6,3,9.5]
40+
}
41+
]
42+
43+
#Averrage of qualifications
44+
def averrage(iterable:list):
45+
return sum(iterable) / len(iterable)
46+
47+
#List with student name and averrage qualifications
48+
list_averrage = list(map(lambda student: [student["name"],averrage(student["qualifications"])],student_list))
49+
50+
print(list_averrage)
51+
52+
#List with student with averrage qualifications bigger than 9
53+
best_students = filter(lambda value: value[1]>=9,list_averrage)
54+
print(list(best_students))
55+
56+
#Order lsit by birth date
57+
birth_date_list=sorted(student_list,key=lambda student:datetime.strptime(student["birth_date"],"%d/%m/%Y"),reverse=True)
58+
print(birth_date_list)
59+
60+
#Bigger qualification
61+
all_qualifications = reduce(lambda x,y: x+y["qualifications"],student_list,[])
62+
print(max(all_qualifications))

0 commit comments

Comments
 (0)