Skip to content

Commit b3d24db

Browse files
authored
Merge pull request #55 from josemoracard/jose4-06-lambda-functions
exercises 06-lambda-functions to 10-Array-Methods
2 parents 3f857d4 + a438081 commit b3d24db

File tree

23 files changed

+113
-85
lines changed

23 files changed

+113
-85
lines changed
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
1-
# `06` Funciones Lambda en Python
1+
# `06` Lambda Functions in Python
22

33
Una **función lambda** es una función con solo una línea de código y sin nombre.
44

5-
Es un tipo de función muy especial en el mundo Python porque puedes usarla como una 'pequeña utilidad' para una programación muy ágil:
5+
Es un tipo de función muy especial en el mundo Python porque puedes usarla como una pequeña utilidad para una programación muy ágil:
66

77
```python
8-
# declarando una función normal para una multiplicación
8+
# Declarando una función normal para una multiplicación
99
def multiply(p1, p2):
1010
return p1 * p2
1111

12-
# declarándola en una línea como una función lambda
12+
# Declarándola en una línea como una función lambda
1313
multiply = lambda p1,p2: p1 * p2
1414
```
1515

16-
1. Las **funciones lambda** tiene que ser siempre muy pequeñas.
16+
### 👉 Caracteristicas:
1717

18-
2. Las **funciones lambda** pueden tener únicamente una línea.
18+
+ Las **funciones lambda** tienen que ser siempre muy pequeñas.
1919

20-
3. Las **funciones lambda** no necesitan un `return`, se asume que lo que haya en esa línea devolverá un valor.
20+
+ Las **funciones lambda** pueden tener únicamente una línea.
2121

22-
4. Las **funciones lambda** pueden almacenarse en variables o ser pasadas como parámetro a otra función.
22+
+ Las **funciones lambda** no necesitan un `return`, se asume que lo que haya en esa línea devolverá un valor.
23+
24+
+ Las **funciones lambda** pueden almacenarse en variables o ser pasadas como parámetro a otra función.
2325

2426

2527
## 📝 Instrucciones:
2628

2729
1. Crea una variable llamada `is_odd`.
2830

29-
2. Asígnale una función lambda que devuelva `True` o `False` dependiendo de si un número dado es impar o no.
31+
2. Asígnale una función **lambda** que devuelva `True` o `False` dependiendo de si un número dado es impar o no.
3032

3133
## 💡 Pista:
3234

3335
+ Así es como declararías una función normal:
3436

3537
```python
36-
# Esta función retorna `True` si el número es impar
38+
# Esta función retorna "True" si el número es impar
3739
def is_odd(num):
3840
return (num % 2) != 0
3941
```

exercises/06-lambda-functions/README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,43 @@ tutorial: "https://www.youtube.com/watch?v=HACQ9uerCuE"
33
---
44

55

6-
# `06` Lambda functions in Python
6+
# `06` Lambda Functions in Python
77

88
A **lambda function** is a function with just one line of code and no name.
99

10-
It is a very special type of funcion in the world of python because you can use it as a small utility for very agile coding:
10+
It is a very special type of function in the world of Python because you can use it as a small utility for very agile coding:
1111

1212
```python
13-
# declaring a normal funcion for multiplication
13+
# Declaring a normal function for multiplication
1414
def multiply(p1, p2):
1515
return p1 * p2
1616

17-
# declaring it now like a one line lambda
17+
# Declaring it now like a one line lambda function
1818
multiply = lambda p1,p2: p1 * p2
1919
```
20-
:point_uo:Facts:
2120

22-
+ **Lambda fuctions** have to be always very small.
21+
### 👉 Facts:
2322

24-
+ **Lambda function** can only have one line.
23+
+ **Lambda functions** have to always be very small.
2524

26-
+ **Lambda function** doesn't need a `return` statement (it is assumed that it will return whatever is on that one line).
25+
+ **Lambda functions** can only have one line.
2726

28-
+ **Lambda functions** can be stored in variables or passed as parameters to another function
27+
+ **Lambda functions** don't need a `return` statement (it is assumed that it will return whatever is on that one line).
28+
29+
+ **Lambda functions** can be stored in variables or passed as parameters to another function.
2930

3031
## 📝 Instructions:
3132

3233
1. Create a variable called `is_odd`.
3334

3435
2. Assign a **lambda function** to it that returns `True` or `False` if a given number is odd.
3536

36-
## 💡Hint
37+
## 💡 Hint
3738

3839
+ Here is how you would declare it like a normal function:
3940

4041
```py
41-
# this function return True if a number is odd.
42+
# This function returns True if a number is odd
4243
def is_odd(num):
4344
return num % 2 != 0
4445
```

exercises/06-lambda-functions/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# your function here
1+
# Your function here
22

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Your function here
2+
3+
is_odd = lambda num: num % 2 != 0

exercises/06-lambda-functions/tests.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import io, sys, pytest, os, re, mock
22

3-
@pytest.mark.it("Declare a function 'is_odd' as lambda")
3+
@pytest.mark.it("Declare a function called 'is_odd' as lambda")
44
def test_declare_variable():
55
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
66
with open(path, 'r') as content_file:
@@ -13,12 +13,12 @@ def test_for_callable(capsys):
1313
import app as app
1414
assert callable(app.is_odd)
1515

16-
@pytest.mark.it('The function is_odd must receive one number and return true if is odd or false otherwise')
16+
@pytest.mark.it('The function is_odd must receive one number and return True if the number is odd or False otherwise')
1717
def test_for_integer(capsys):
1818
import app as app
1919
assert app.is_odd(3) == True
2020

2121
@pytest.mark.it('We tested the function with 2 and the result was not False')
2222
def test_for_integer2(capsys):
2323
import app as app
24-
assert app.is_odd(2) == False
24+
assert app.is_odd(2) == False
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
# `07` Funciones Lambda
1+
# `07` Lambda Functions
22

3-
4-
**:point_up: Recuerda:**
3+
### ☝ Recuerda:
54

65
Las funciones Lambda permiten una sintaxis corta para escribir expresiones de funciones.
76

87
```python
9-
multy = lambda x, y: x * y
10-
print(multy(2,2))
8+
multiply = lambda x, y: x * y
9+
print(multiply(2,2))
1110
```
1211

1312
## 📝 Instrucciones:
@@ -18,4 +17,4 @@ print(multy(2,2))
1817

1918
## 💡 Pista:
2019

21-
+ Busca en Google "remove last letter form string python" (puedes usar los corchetes).
20+
+ Busca en Google "como eliminar el último caracter de un string python" (puedes usar los corchetes).

exercises/07-lambda-function-two/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
tutorial: "https://www.youtube.com/watch?v=1HwmTkQPeMo"
33
---
44

5-
# `07` Lambda functions
5+
# `07` Lambda Functions
66

7-
**:point_up: Remember:**
7+
### Remember:
88

9-
Lambda functions allows a short syntax for writing function expressions.
9+
Lambda functions allow a short syntax for writing function expressions.
1010

1111
```python
12-
multy = lambda x, y: x * y
13-
print(multy(2,2))
12+
multiply = lambda x, y: x * y
13+
print(multiply(2,2))
1414
```
1515

1616
## 📝 Instructions:
1717

18-
1. Create a lambda function called `rapid` it will take one string parameter.
18+
1. Create a lambda function called `rapid`, which will take one string parameter.
1919

2020
2. Return the same string with the last letter removed.
2121

22-
## 💡 Hint
22+
## 💡 Hint:
2323

24-
+ Google how to "remove last letter form string python" (you can use the square brackets).
24+
+ Google "how to remove last letter from string python" (you can use the square brackets).
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22

33

4-
# From this line above, plese do not change code below
5-
print(rapid("bob")) #should print bo
4+
# Your code above, please do not change code below
5+
print(rapid("bob")) # Should print "bo"
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
rapid = lambda myStr: myStr[:-1]
22

3-
4-
# From this line above, plese do not change code below
5-
print(rapid("bob")) #should print bo
3+
# Your code above, please do not change code below
4+
print(rapid("bob")) # Should print "bo"

exercises/07-lambda-function-two/tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import io, sys, pytest, os, re, mock
22

3-
@pytest.mark.it("Declare a function 'rapid' as lambda")
3+
@pytest.mark.it("Declare a function called 'rapid' as lambda")
44
def test_declare_variable():
55
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
66
with open(path, 'r') as content_file:
@@ -12,7 +12,7 @@ def test_declare_variable():
1212
def test_for_callable(capsys):
1313
from app import rapid
1414

15-
@pytest.mark.it('The function rapid must receive one string and return the same but without the last letter (make sure it\'s lowecase)')
15+
@pytest.mark.it('The function rapid must receive one string and return the same string without the last character')
1616
def test_for_integer(capsys):
1717
from app import rapid
1818
assert rapid("maria") == "mari"

0 commit comments

Comments
 (0)