forked from horaciourena/pythontutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlambdaFunctions.py
53 lines (38 loc) · 1.01 KB
/
lambdaFunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# # Funciones anonimas
# # Solo se ejecutan una unica vez
# # No poseen nombre
# # Map Function
# def potencia2(num):
# return num**2
# nums = [1,2,3,4,5]
# for item in map(potencia2,nums):
# print(item)
# print(list(map(potencia2,nums)))
# def separador(mystring):
# if len(mystring)%2==0:
# return 'Par'
# else:
# return mystring[0]
nombres = ['Sally', 'Carlos', 'Casey', 'Mercedes']
# print(list(map(separador,nombres)))
# # Filter Function
# def numPar(n):
# return n%2==0
myNumbers = [1,2,3,4,5,6]
# print(list(filter(numPar,myNumbers)))
# for i in myNumbers:
# print(i)
# Lambda Expresions
def potencia2(n):
resultado = n**2
return resultado
def potencia22(n):
return n**2
def potencia23(n): return n**2
lambda n: n**2
potencia = lambda n: n**2
print(potencia(5))
print(list(map(lambda num: num**2,myNumbers)))
print(list(filter(lambda num: num%2==0,myNumbers)))
print(list(map(lambda name: name[0],nombres)))
print(list(map(lambda name: name[::-1],nombres)))