Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 163 additions & 37 deletions your-code/main.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"NOTE: I used list comprehensions in most of the cases even if we haven't seen them yet. Hope it's not a problem."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -9,7 +16,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -25,11 +32,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"PLAY\n",
"FILLING\n",
"BAR\n",
"THEATRE\n",
"EASYGOING\n",
"DATE\n",
"LEAD\n",
"THAT\n",
"STORY\n",
"ISLAND\n"
]
}
],
"source": [
"# your code here"
"for word in words:\n",
" print(word.upper())"
]
},
{
Expand All @@ -41,11 +66,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"['filling', 'theatre', 'easygoing', 'story', 'island']"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here"
"words5_and_above = [word for word in words if len(word) >= 5]\n",
"words5_and_above"
]
},
{
Expand All @@ -57,11 +94,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"theatre\n"
]
}
],
"source": [
"# your code here"
"for word in words:\n",
" if word[0] == 't':\n",
" print(word)\n",
" break"
]
},
{
Expand All @@ -80,11 +128,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here"
"squares = [i**2 for i in range(1, 11)]\n",
"squares"
]
},
{
Expand All @@ -96,11 +156,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[1, 9, 25, 49, 81]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here"
"squares_odd = [i**2 for i in range(1, 11) if i%2 != 0]\n",
"squares_odd"
]
},
{
Expand All @@ -116,7 +188,7 @@
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"squares_below_thousand = [i**2 for i in range(1000) if i%8 == 0]"
]
},
{
Expand All @@ -128,7 +200,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -170,11 +242,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"There are 5 of them\n"
]
}
],
"source": [
"# your code here"
"print(f'There are {len(people)} of them')"
]
},
{
Expand All @@ -186,11 +266,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4 people have kids\n"
]
}
],
"source": [
"# your code here"
"number_kids = len([person for person in people if person['n_kids'] > 0])\n",
"print(f'{number_kids} people have kids')"
]
},
{
Expand All @@ -202,11 +291,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"10"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here"
"sum([person['n_kids'] for person in people])"
]
},
{
Expand All @@ -218,17 +318,48 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Congrats Sonia! ;-)!\n",
"Congrats Lucía! ;-)!\n"
]
},
{
"data": {
"text/plain": [
"[{'name': 'Juan', 'age': 34, 'n_kids': 2},\n",
" {'name': 'Pepe', 'age': 27, 'n_kids': 0},\n",
" {'name': 'Sonia', 'age': 41, 'n_kids': 2},\n",
" {'name': 'Lucía', 'age': 22, 'n_kids': 3},\n",
" {'name': 'Leo', 'age': 55, 'n_kids': 5}]"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# your code here"
"people_after_year = []\n",
"for person in people:\n",
" # create new object to avoid changes in original list of persons\n",
" temp_data = dict(person)\n",
" if person['name'][-1].lower() == 'a':\n",
" temp_data['n_kids'] += 1\n",
" print(f'Congrats {person['name']}! ;-)!')\n",
" people_after_year.append(temp_data)\n",
"people_after_year"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "ironhack",
"language": "python",
"name": "python3"
},
Expand All @@ -242,7 +373,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.13.0"
},
"toc": {
"base_numbering": 1,
Expand Down Expand Up @@ -285,11 +416,6 @@
"_Feature"
],
"window_display": false
},
"vscode": {
"interpreter": {
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
}
}
},
"nbformat": 4,
Expand Down