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
136 changes: 117 additions & 19 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The sum of the grades is: 7\n",
"Sorted list of the performance of 3 students: [0, 0, 0]\n",
"The number of occurrences of the score '5' is: 0\n"
]
}
],
"source": [
"# Your code here"
"students_grades = []\n",
"for i in range(5):\n",
" grades_input = int(input(\"Enter the grade of each student: \"))\n",
" students_grades.append(grades_input)\n",
"\n",
"sum_grades = sum(students_grades)\n",
"students_selection = students_grades[0:5:2]\n",
"students_selection.sort()\n",
"\n",
"print (f\"The sum of the grades is: {sum_grades}\")\n",
"print (f\"Sorted list of the performance of {len(students_selection)} students: {students_selection}\")\n",
"print (\"The number of occurrences of the score '5' is:\", students_selection.count(5))"
]
},
{
Expand Down Expand Up @@ -97,11 +118,39 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('banana', 'grape')\n",
"('banana', 'kiwi', 'pineapple', 'watermelon', 'grape')\n",
"('banana', 'kiwi', 'pineapple', 'watermelon', 'grape', 'apple', 'melon')\n",
"('banana', 'kiwi', 'pineapple', 'watermelon', 'grape', 'banana', 'kiwi', 'pineapple', 'grape', 'apple', 'melon') 11\n"
]
}
],
"source": [
"# Your code here"
"fruits = (\"banana\", \"orange\", \"pineapple\", \"watermelon\", \"grape\")\n",
"print(fruits[0:5:4])\n",
"list_fruits = list(fruits)\n",
"list_fruits[1] = \"kiwi\"\n",
"fruits = tuple(list_fruits)\n",
"print(fruits)\n",
"extra_fruits = (\"apple\",\"melon\")\n",
"new_fruits = fruits + extra_fruits\n",
"print(new_fruits)\n",
"first_fruits = new_fruits[0:3]\n",
"last_fruits = new_fruits[4:7]\n",
"mega_fruits = fruits + first_fruits + last_fruits\n",
"print(mega_fruits, len(mega_fruits))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -136,7 +185,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -163,11 +212,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"21\n",
"23\n",
"['end', 'enough', 'had', 'i', 'if', 'it', 'ive', 'know', 'of', 'say', 'some', 'that', 'think', 'those', 'to', 'what', 'who', 'with']\n"
]
}
],
"source": [
"# Your code here"
"join_poem = ' '.join(poem.split(' ')) # covierto a lista usando espacios y vuelvo a unir con un solo espacio. Elimino espacios simple, dobles...\n",
"join_new_poem = ' '.join(new_poem.split(' '))\n",
"clean_poem = join_poem.replace(\".\",\"\").replace(\",\",\"\").replace(\"’\",\"\").lower().split(\" \") # elimino signos de puntiacion y convierto a lista usando como separador los espacios blancos\n",
"clean_new_poem = join_new_poem.replace(\".\",\"\").replace(\",\",\"\").replace(\"'\",\"\").lower().split(\" \") # No convierto aun a set porque me separía por letras y no por palabras al ser aun un string\n",
"set_poem = set(clean_poem) # convierto a ser la lista \n",
"set_new_poem = set(clean_new_poem)\n",
"unique_words_poem = set_poem - set_new_poem\n",
"unique_words_new_poem = set_new_poem - set_poem\n",
"print(len(unique_words_poem))\n",
"print(len(unique_words_new_poem))\n",
"unique_words = set_poem & set_new_poem\n",
"print(sorted(unique_words))"
]
},
{
Expand All @@ -193,7 +263,7 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -206,7 +276,8 @@
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"grades[\"Bob\"][\"Philosophy\"] = 100\n",
"print(grades)"
]
},
{
Expand Down Expand Up @@ -239,14 +310,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}\n"
]
}
],
"source": [
"keys = ['Physics', 'Math', 'Chemistry', 'Philosophy']\n",
"values = [75, 85, 60,90]\n",
"\n",
"# Your code here"
"subject_scores_dict = dict(zip(keys,values))\n",
"\n",
"\n",
"print(subject_scores_dict)"
]
},
{
Expand Down Expand Up @@ -275,17 +357,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Chemistry\n"
]
}
],
"source": [
"# Your code here"
"min_subject = min(subject_scores_dict, key=subject_scores_dict.get)\n",
"print(min_subject)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -299,7 +397,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.4"
}
},
"nbformat": 4,
Expand Down