From 0a37772206a57fee5364fa97002dc21f043aa2db Mon Sep 17 00:00:00 2001 From: Salvador Cruz de Bustos Date: Thu, 17 Sep 2026 18:29:04 +0200 Subject: [PATCH] Update lab-python-data-structures.ipynb --- lab-python-data-structures.ipynb | 185 ++++++++++++++++++++++++++++--- 1 file changed, 169 insertions(+), 16 deletions(-) diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 8ba652c..a0c12ff 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -57,11 +57,59 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "23\n", + "[5, 3, 5, 4, 6]\n", + "[5, 5, 6]\n" + ] + }, + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "notas = []\n", + "\n", + "alumno1 = int(input(\"nota1\"))\n", + "alumno2 = int(input(\"nota2\"))\n", + "alumno3 = int(input(\"nota3\"))\n", + "alumno4 = int(input(\"nota4\"))\n", + "alumno5 = int(input(\"nota5\"))\n", + "\n", + "todas_las_notas = alumno1 + alumno2 + alumno3 + alumno4 + alumno5\n", + "print(todas_las_notas)\n", + "\n", + "notas.append(alumno1)\n", + "notas.append(alumno2)\n", + "notas.append(alumno3)\n", + "notas.append(alumno4)\n", + "notas.append(alumno5)\n", + "print(notas)\n", + "\n", + "notas2 = []\n", + "notas2 = notas[0:6:2]\n", + "notas.sort()\n", + "print(notas2)\n", + "\n", + "len(notas2)\n", + "notas2.count(5)\n", + "\n", + "\n", + "\n" ] }, { @@ -95,11 +143,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "banana melon\n", + "['banana', 'uva', 'tomate', 'sandia', 'melon']\n", + "['banana', 'uva', 'tomate', 'sandia', 'melon', 'naranja', 'manzana']\n", + "{'banana', 'tomate', 'uva'}\n", + "{'naranja', 'melon', 'sandia'}\n", + "{'naranja', 'banana', 'manzana', 'uva', 'tomate', 'melon', 'sandia'}\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "frutas = (\"banana\", \"kiwi\", \"tomate\", \"sandia\", \"melon\")\n", + "print(type(frutas))\n", + "\n", + "print(frutas[0], frutas[-1])\n", + "\n", + "frutas_lista = [\"banana\", \"kiwi\", \"tomate\", \"sandia\", \"melon\"]\n", + "frutas_lista[1] = \"uva\"\n", + "\n", + "frutas_nuevas = []\n", + "frutas_nuevas = frutas_lista + [\"naranja\", \"manzana\"]\n", + "print(frutas_lista)\n", + "print(frutas_nuevas)\n", + "\n", + "frutas1 = {\"banana\", \"uva\", \"tomate\"}\n", + "frutas2 = {\"sandia\", \"melon\", \"naranja\"}\n", + "frutas3 = {\"banana\", \"uva\", \"tomate\",\"sandia\", \"melon\", \"naranja\", \"manzana\"}\n", + "\n", + "print(frutas1)\n", + "print(frutas2)\n", + "print(frutas3)\n", + "\n", + "frutas4 = frutas1 & frutas2\n", + "frutas5 = frutas3 & frutas4\n", + "\n", + "\n", + "\n" ] }, { @@ -136,7 +224,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, "outputs": [], "source": [ @@ -163,11 +251,66 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'A', '’', 'c', 'p'}\n", + "{'b', \"'\", 'q'}\n" + ] + }, + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "set1 = set(poem)\n", + "set2 = set(new_poem)\n", + "\n", + "setpoem = set1 - set2\n", + "print(setpoem)\n", + "len(setpoem)\n", + "\n", + "setnewpoem = set2 - set1\n", + "print(setnewpoem)\n", + "len(setnewpoem)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'g', 'B', 'u', 'f', '.', 'k', 'v', 'S', 'I', ' ', 'T', 'h', 'r', 'l', 'y', 'd', 'n', '\\n', ',', 'a', 'e', 'w', 'o', 't', 's', 'm', 'F', 'i'}\n", + "{'g', 'B', 'u', 'f', '.', 'k', 'v', 'S', 'I', ' ', 'T', 'h', 'r', 'l', 'y', 'd', 'n', '\\n', ',', 'a', 'e', 'w', 'o', 't', 's', 'm', 'F', 'i'}\n", + "['\\n', ' ', ',', '.', 'B', 'F', 'I', 'S', 'T', 'a', 'd', 'e', 'f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'o', 'r', 's', 't', 'u', 'v', 'w', 'y']\n" + ] + } + ], + "source": [ + "total = set(set1 & set2)\n", + "total_lista = set(total)\n", + "total_ordenado = sorted(total_lista)\n", + "\n", + "print(total)\n", + "print(total_lista)\n", + "print(total_ordenado)" ] }, { @@ -193,7 +336,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 78, "metadata": {}, "outputs": [], "source": [ @@ -202,11 +345,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 83, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Alice': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}, 'Bob': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 100}}\n" + ] + } + ], "source": [ - "# Your code here" + "# Your code here\n", + "grades[\"Bob\"][\"Philosophy\"] = 100\n", + "print(grades)" ] }, { @@ -285,7 +438,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -299,7 +452,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.6" } }, "nbformat": 4,