Skip to content

Commit d9a4e02

Browse files
authored
Merge pull request 4GeeksAcademy#116 from josemoracard/jose7-12.2-Map_function_inside_variable
exercises 12.2-Map_function_inside_variable to 16-Techno_beat
2 parents 7c64f4a + 9411754 commit d9a4e02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+458
-314
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
!/exercises/*
1414

1515
*.pyc
16-
__pycache__/
16+
1717
.pytest_cache/
1818

1919
!/.learn

exercises/12.2-Map_function_inside_variable/README.es.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# `12.2` Map function inside a variable
22

3-
La variable names contiene muchos nombres 😒 (daah...)
3+
La variable `names` contiene muchos nombres (😒 daah...)
44

5-
La función `prepender` almacenada en la variable devuelve lo que sea que se le pase pero agregando antes: `'My name is:'`
5+
La función ya definida `prepender` devuelve lo que sea que se le pase pero agregando antes: `'My name is: '`.
66

77
## 📝 Instrucciones:
88

99
1. Por favor, mapea la lista de nombres usando la función `prepender` para crear una nueva lista que se parezca a esto:
1010

11-
## Resultado Esperado:
11+
## 💻 Resultado esperado:
1212

1313
```py
1414
[ 'My name is: Alice',

exercises/12.2-Map_function_inside_variable/README.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
# `12.2` Map function inside a variable
22

3-
The variable names contains a lot of names (:unamused: dugh...)
3+
The variable `names` contains a lot of names (😒 duh...)
44

5-
The function stored in the variable `prepender` returns whatever is passed to it but prepended with the string: `'My name is:'`.
5+
The already defined function `prepender` returns whatever is passed to it but is prepended with the string: `'My name is: '`.
66

7-
## 📝Instructions:
7+
## 📝 Instructions:
88

9-
1. Please map the names list using the `prepender` function
10-
to create a new list that looks like this:
9+
1. Please map the names list using the `prepender` function to create a new list that looks like this:
1110

12-
## Expected Result:
11+
## 💻 Expected result:
1312

1413
```py
1514
[ 'My name is: Alice',
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
names = ['Alice','Bob','Marry','Joe','Hilary','Stevia','Dylan']
1+
names = ['Alice', 'Bob', 'Marry', 'Joe', 'Hilary', 'Stevia', 'Dylan']
22

33
def prepender(name):
44
return "My name is: " + name
5-
#Your code go here:
5+
6+
# Your code here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
names = ['Alice', 'Bob', 'Marry', 'Joe', 'Hilary', 'Stevia', 'Dylan']
2+
3+
def prepender(name):
4+
return "My name is: " + name
5+
6+
# Your code here
7+
8+
new_list = list(map(prepender, names))
9+
10+
print(new_list)
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import io, sys, pytest, os, re
22
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
33

4-
@pytest.mark.it("Print the all the names as in the output")
4+
@pytest.mark.it("Print all the names as in the output")
55
def test_multp(capsys, app):
66
import app
77
captured = capsys.readouterr()
@@ -11,4 +11,4 @@ def test_multp(capsys, app):
1111
def test_map():
1212
f = open(os.path.dirname(os.path.abspath(__file__)) + '/app.py')
1313
content = f.read()
14-
assert content.find("map") > 0
14+
assert content.find("map") > 0

exercises/12.3-Map_data_types/README.es.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
# `12.3` Map data type
1+
# `12.3` Map data types
22

33
Muchas veces las listas vienen con valores mixtos y necesitamos unificarlos dentro de un solo tipo de datos.
44

55
## 📝 Instrucciones:
66

77
1. Actualiza la función `type_list()` para hacer que cree una nueva lista (`new_list`) que contenga el tipo de dato que corresponde a cada elemento de la lista original.
88

9-
## 💡 Pista:
9+
## 💡 Pistas:
1010

1111
+ Usa la función `type()` para obtener el tipo de dato.
1212

1313
+ Más sobre tipos de datos: https://www.w3schools.com/python/python_datatypes.asp
1414

15-
## Resultado esperado:
15+
## 💻 Resultado esperado:
1616

1717
```py
1818
[<class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'int'>, <class 'int'>]

exercises/12.3-Map_data_types/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# `12.3` Map data types
22

3-
Some times lists come with mixed values and you need to unify them into only one data type.
3+
Sometimes lists come with mixed values, and you need to unify them into only one data type.
44

5-
## 📝Instructions:
5+
## 📝 Instructions:
66

7-
1. Update the map function to make it create a **new list** that contains the data types of each corresponding item from the original list.
7+
1. Update the `type_list` function to make it create a `new_list` that contains the data types of each corresponding item from the original list.
88

9-
## 💡 Hint:
9+
## 💡 Hints:
1010

1111
+ Use the `type()` function to get the data type.
1212

1313
+ More about data type: https://www.w3schools.com/python/python_datatypes.asp
1414

15-
## Expected result:
15+
## 💻 Expected result:
1616

1717
```py
1818
[<class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'str'>, <class 'int'>, <class 'int'>]

exercises/12.3-Map_data_types/app.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
list_Strings = ['1','5','45','34','343','34',6556,323]
2-
1+
mixed_list = ['1','5','45','34','343','34',6556,323]
32

43
def type_list(items):
5-
return items
4+
# Your code here
5+
return
6+
7+
new_list = list(map(type_list, mixed_list))
68

7-
new_list = list(map(type_list, list_Strings))
8-
print(new_list)
9+
print(new_list)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mixed_list = ['1','5','45','34','343','34',6556,323]
2+
3+
def type_list(items):
4+
# Your code here
5+
return type(items)
6+
7+
new_list = list(map(type_list, mixed_list))
8+
9+
print(new_list)

exercises/12.3-Map_data_types/test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import io, sys, pytest, os, re
22
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
33

4-
@pytest.mark.it("Print all data types of the list")
4+
@pytest.mark.it("Print all data types from the mixed_list")
55
def test_multp(capsys, app):
66
import app
77
captured = capsys.readouterr()
@@ -11,4 +11,4 @@ def test_multp(capsys, app):
1111
def test_map():
1212
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
1313
content = f.read()
14-
assert content.find("map") > 0
14+
assert content.find("map") > 0

exercises/12.4-Map_list_of_objects/README.es.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
# `12.4` Map a list of objects
2-
3-
El escenario más común para la función de mapeo es simplificar listas dadas, por ejemplo:
4-
5-
El actual algoritmo crea una lista con solo los nombres de personas (`name_list`) y los imprime en la consola.
1+
# `12.4` Map a list of dictionaries
62

73
## 📝 Instrucciones:
84

9-
1. En este momento la función está imprimiendo solo los nombres. Por favor, actualiza la función de mapeo, de modo que cree una lista donde cada elemento contenga lo siguiente:
5+
1. En este momento la función `format_greeting` está imprimiendo solo los nombres. Por favor, actualiza la función de mapeo, de modo que cree una lista donde cada elemento contenga lo siguiente:
6+
7+
```py
8+
'Hello, my name is <name> and I am <age> years old'
9+
```
1010

11-
`Hello my name is <name> and I am <age> years old.`
11+
## 💡 Pistas:
1212

13-
## 💡 Pista:
13+
- Tienes que obtener la edad de cada persona de acuerdo a su fecha de nacimiento (`birth_date`).
1414

15-
- Tienes que obtener la edad de cada persona de acuerdo a su cumpleaños (`birthDate`).
15+
- Tómate tu tiempo para entender la función ya definida `calculate_age`.
1616

17-
- Busca en Google "como obtener una fecha de nacimiento dada en python.
17+
- Busca en Google "cómo obtener la edad de alguien dada su fecha de nacimiento python".
1818

19-
- Dentro de tu función de simplificación debes devolver una concatenación.
19+
- Dentro de tu función `format_greeting` debes devolver una concatenación.
2020

21-
## Resultado esperado:
21+
## 💻 Resultado esperado:
2222

23-
La salida esperada debería ser similar a esta:
23+
Debe quedar algo similar a esto, sin embargo, las edades pueden variar.
2424

2525
```py
2626
[ 'Hello, my name is Joe and I am 32 years old',

exercises/12.4-Map_list_of_objects/README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
# `12.4` Map a list of objects
2-
3-
The most common scenario for the mapping function is for simplifying given lists, for example:
4-
5-
The current algorithm creates a list with only the names of the people and prints it on the console.
1+
# `12.4` Map a list of dictionaries
62

73
## 📝 Instructions:
84

9-
1. At this time the function is printing the names only. Please update the mapping function so it creates a list where each item contains the following:
5+
1. At this time, the function `format_greeting` is printing the names only. Please update the mapping function so it creates a list where each item contains the following:
6+
7+
```py
8+
'Hello, my name is <name> and I am <age> years old'
9+
```
1010

11-
`Hello, my name is Joe and I am 13 years old`
11+
## 💡 Hints:
1212

13-
## 💡 Hint:
13+
+ You have to get the age of each person based on their `birth_date`.
1414

15-
+ You have to get the age of each people based on their `birthDate`.
15+
+ Take your time to understand the already defined `calculate_age` function.
1616

17-
+ Search in Google "How to get the age of given birth date in python"
17+
+ Search in Google "How to get the age of a given birth date in python".
1818

19-
+ Inside your simplifier function you have to return a concatenation.
19+
+ Inside your `format_greeting` function you have to return a concatenation.
2020

21-
## Expected result:
21+
## 💻 Expected result:
2222

23-
The expected output should look similar but not exactly to this:
23+
The result should be similar to this, but the ages might be different.
2424

2525
```py
2626
[ 'Hello, my name is Joe and I am 32 years old',
+14-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import datetime
22

3-
43
people = [
5-
{ "name": 'Joe', "birthDate": datetime.datetime(1986,10,24) },
6-
{ "name": 'Bob', "birthDate": datetime.datetime(1975,5,24) },
7-
{ "name": 'Erika', "birthDate": datetime.datetime(1989,6,12) },
8-
{ "name": 'Dylan', "birthDate": datetime.datetime(1999,12,14) },
9-
{ "name": 'Steve', "birthDate": datetime.datetime(2003,4,24) }
4+
{ "name": 'Joe', "birth_date": datetime.datetime(1986,10,24) },
5+
{ "name": 'Bob', "birth_date": datetime.datetime(1975,5,24) },
6+
{ "name": 'Erika', "birth_date": datetime.datetime(1989,6,12) },
7+
{ "name": 'Dylan', "birth_date": datetime.datetime(1999,12,14) },
8+
{ "name": 'Steve', "birth_date": datetime.datetime(2003,4,24) }
109
]
1110

12-
13-
def calculateAge(birthDate):
11+
def calculate_age(date_of_birth):
1412
today = datetime.date.today()
15-
age = today.year - birthDate.year - ((today.month, today.day) < (birthDate.month, birthDate.day))
13+
age = today.year - date_of_birth.year - ((today.month, today.day) < (date_of_birth.month, date_of_birth.day))
1614
return age
1715

18-
name_list = list(map(lambda person: person["name"] , people))
19-
print(name_list)
16+
def format_greeting(person):
17+
# Your code here
18+
return person["name"]
2019

20+
21+
name_list = list(map(format_greeting, people))
22+
23+
print(name_list)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import datetime
2+
3+
people = [
4+
{ "name": 'Joe', "birth_date": datetime.datetime(1986,10,24) },
5+
{ "name": 'Bob', "birth_date": datetime.datetime(1975,5,24) },
6+
{ "name": 'Erika', "birth_date": datetime.datetime(1989,6,12) },
7+
{ "name": 'Dylan', "birth_date": datetime.datetime(1999,12,14) },
8+
{ "name": 'Steve', "birth_date": datetime.datetime(2003,4,24) }
9+
]
10+
11+
def calculate_age(date_of_birth):
12+
today = datetime.date.today()
13+
age = today.year - date_of_birth.year - ((today.month, today.day) < (date_of_birth.month, date_of_birth.day))
14+
return age
15+
16+
def format_greeting(person):
17+
# Your code here
18+
name = person["name"]
19+
age = calculate_age(person["birth_date"])
20+
return f"Hello, my name is {name} and I am {age} years old"
21+
22+
name_list = list(map(format_greeting, people))
23+
24+
print(name_list)

exercises/12.4-Map_list_of_objects/test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import io, sys, pytest, os, re, datetime
22
path = os.path.dirname(os.path.abspath(__file__))+'/app.py'
33

4-
@pytest.mark.it("Each element needs to have this output: !!😎")
4+
@pytest.mark.it("Each element should to have the correct output")
55
def test_multp(capsys, app):
66
import app
77
people = [
@@ -19,7 +19,7 @@ def calculateAge(birthDate):
1919
captured = capsys.readouterr()
2020
assert str(name_list) in captured.out
2121

22-
@pytest.mark.it("Use the map function ")
22+
@pytest.mark.it("Use the map function")
2323
def test_map():
2424
f = open(os.path.dirname(os.path.abspath(__file__))+'/app.py')
2525
content = f.read()

exercises/12.5-Yes_and_no/README.es.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,23 @@
22

33
## 📝 Instrucciones:
44

5-
1. Por favor, usa la funcionalidad de mapeo de lista para iterar la lista de buleanos y crear una nueva lista que contenga el texto `'wiki'` por cada 1 y `'woko'` por cada 0 que tenga la lista original.
5+
1. Por favor, usa la funcionalidad de mapeo de lista para iterar la lista de booleanos y crear una nueva lista que contenga el texto `'wiki'` por cada `1` y `'woko'` por cada `0` de la lista original.
66

77
2. Imprime la nueva lista en la consola.
88

9-
## 💡 Pista:
9+
## 💡 Pistas:
1010

1111
- Debes mapear la lista entera.
1212

1313
- Dentro de tu función de mapeo necesitas usar un condicional para verificar si el valor actual es `1` o `0`.
1414

15-
- Si el valor es 1 asignas el texto `'wiki'`.
15+
- Si el valor es `1` asignas el texto `'wiki'`.
1616

17-
- Si el valor es 0 asignas el texto `'woko'`.
17+
- Si el valor es `0` asignas el texto `'woko'`.
1818

19-
## Resultado esperado:
19+
## 💻 Resultado esperado:
2020

2121
```py
22-
23-
[ 'woko', 'wiki', 'woko', 'woko', 'wiki', 'wiki', 'wiki', 'woko', 'woko', 'wiki', 'woko', 'wiki', 'wiki', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'wiki', 'woko', 'woko', 'woko', 'woko', 'wiki' ]
22+
[ 'woko', 'wiki', 'woko', 'woko', 'wiki', 'wiki', 'wiki', 'woko', 'woko', 'wiki', 'woko', 'wiki', 'wiki', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'wiki', 'woko', 'woko', 'woko', 'woko', 'wiki' ]
2423
```
2524

exercises/12.5-Yes_and_no/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# `12.5` Yes and no
22

3-
## 📝Instructions:
3+
## 📝 Instructions:
44

5-
1. Please use the list map functionality to loop the list of booleans and create a new list that contains the string `'wiki'` for every `1` and `'woko'` for every `0` that the original list had.
5+
1. Please use the map functionality to loop the list of booleans and create a new list that contains the string `'wiki'` for every `1` and `'woko'` for every `0` that the original list had.
66

77
2. Print that list on the console.
88

9-
## 💡 Hint:
9+
## 💡 Hints:
1010

1111
+ You need to map the entire list.
1212

1313
+ Inside your mapping function you need to use a conditional to verify if the current value is `0` or `1`.
1414

15-
+ If the current value is 1 you print the string `'wiki'`.
15+
+ If the current value is `1` you print the string `'wiki'`.
1616

17-
+ If the current value is 0 you print the string `'woko'`.
17+
+ If the current value is `0` you print the string `'woko'`.
1818

19-
## Expected result:
19+
## 💻 Expected result:
2020

2121
```py
22-
[ 'woko', 'wiki', 'woko', 'woko', 'wiki', 'wiki', 'wiki', 'woko', 'woko', 'wiki', 'woko', 'wiki', 'wiki', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'wiki', 'woko', 'woko', 'woko', 'woko', 'wiki' ]
22+
[ 'woko', 'wiki', 'woko', 'woko', 'wiki', 'wiki', 'wiki', 'woko', 'woko', 'wiki', 'woko', 'wiki', 'wiki', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'woko', 'wiki', 'woko', 'woko', 'woko', 'woko', 'wiki' ]
2323
```

0 commit comments

Comments
 (0)